Developers
Start building
Themes/Theme SDK/Modules/data/Hooks: useCollectionListEntry to usePost

Hooks: useCollectionListEntry to usePost

The hooks of @poltura/theme-sdk/data, useCollectionListEntry to usePost.

On this page
import { … } from '@poltura/theme-sdk/data';

useCollectionListEntry

One pick of a collectionList setting, read as a card: its title, page and image.

useCollectionListEntry(pick: CollectionListPick, options: SuspenseQueryOptions): SuspenseQueryResult<CollectionListEntry | null>
useCollectionListEntry(pick: CollectionListPick, options?: QueryOptions): QueryResult<CollectionListEntry | null>

Parameters

  • pick: CollectionListPick: One entry of the setting's value.
  • options: SuspenseQueryOptions: Suspense, idling and keeping the previous entry while the next loads.

Returns: The collection or category, or null when the store has none by that URL segment.

Example

import { useCollectionListEntry, type CollectionListPick } from '@poltura/theme-sdk/data';

export function Tile({ pick }: { pick: CollectionListPick }) {
  const { data } = useCollectionListEntry(pick, { suspense: true });
  return data ? <a href={data.href}>{data.title}</a> : null;
}

usePage

The site page a page setting points to.

usePage(path: string | undefined, options: SuspenseQueryOptions): SuspenseQueryResult<ContentEntry | null>
usePage(path: string | undefined, options?: QueryOptions): QueryResult<ContentEntry | null>

Parameters

  • path: string | undefined: The setting's value, such as /about; undefined reads nothing.
  • options: SuspenseQueryOptions: Suspense, idling and keeping the previous page while the next loads.

Returns: The page, or null when none is published there or the setting is empty.

Example

import { usePage } from '@poltura/theme-sdk/data';

export function PageLink({ path }: { path?: string }) {
  const { data } = usePage(path);
  return data ? <a href={data.href}>{data.title}</a> : null;
}

usePost

The blog post or guide a post setting points to.

usePost(post: PostLookup | undefined, options: SuspenseQueryOptions): SuspenseQueryResult<ContentEntry | null>
usePost(post: PostLookup | undefined, options?: QueryOptions): QueryResult<ContentEntry | null>

Parameters

  • post: PostLookup | undefined: The setting's value; undefined reads nothing.
  • options: SuspenseQueryOptions: Suspense, idling and keeping the previous post while the next loads.

Returns: The post, or null when it is not live or the setting is empty.

Example

import { usePost, type PostLookup } from '@poltura/theme-sdk/data';

export function FeaturedPost({ post }: { post?: PostLookup }) {
  const { data } = usePost(post);
  return data ? <a href={data.href}>{data.title}</a> : null;
}
Last updated