Skip to content

Commit

Permalink
feat: add usePrismicDocumentsByUIDs and useAllPrismicDocumentsByUIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloashmore committed Oct 9, 2021
1 parent fef36bc commit 3a25db8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/hooks.ts
Expand Up @@ -155,6 +155,56 @@ export const usePrismicDocumentByUID = <
): ClientHookReturnType<TDocument> =>
useStatefulPrismicClientMethod(proto.getByUID, args);

/**
* A hook that queries documents from the Prismic repository with specific UIDs
* of a Custom Type.
*
* @remarks
* An additional `@prismicio/client` instance can be provided at `params.client`.
* @typeParam TDocument - Type of the Prismic document returned
* @param documentType - The API ID of the document's Custom Type
* @param uids - A list of document UIDs.
* @param params - Parameters to filter, sort, and paginate results
*
* @returns The composable payload {@link ClientHookReturnType}
* @see Underlying `@prismicio/client` method {@link proto.getByUID}
*/
export const usePrismicDocumentsByUIDs = <
TDocument extends prismicT.PrismicDocument,
>(
...args: [
documentType: ClientMethodParameters<"getByUIDs">[0],
uids: ClientMethodParameters<"getByUIDs">[1],
params?: ClientMethodParameters<"getByUIDs">[2] & HookOnlyParameters,
]
): ClientHookReturnType<prismicT.Query<TDocument>> =>
useStatefulPrismicClientMethod(proto.getByUIDs, args);

/**
* A hook that queries all documents from the Prismic repository with specific
* UIDs of a Custom Type.
*
* @remarks
* An additional `@prismicio/client` instance can be provided at `params.client`.
* @typeParam TDocument - Type of the Prismic document returned
* @param documentType - The API ID of the document's Custom Type
* @param uids - A list of document UIDs.
* @param params - Parameters to filter, sort, and paginate results
*
* @returns The composable payload {@link ClientHookReturnType}
* @see Underlying `@prismicio/client` method {@link proto.getByUID}
*/
export const useAllPrismicDocumentsByUIDs = <
TDocument extends prismicT.PrismicDocument,
>(
...args: [
documentType: ClientMethodParameters<"getByUIDs">[0],
uids: ClientMethodParameters<"getByUIDs">[1],
params?: ClientMethodParameters<"getByUIDs">[2] & HookOnlyParameters,
]
): ClientHookReturnType<TDocument[]> =>
useStatefulPrismicClientMethod(proto.getAllByUIDs, args);

/**
* A hook that queries a singleton document from the Prismic repository for a
* specific Custom Type.
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Expand Up @@ -36,6 +36,7 @@ export {
useAllPrismicDocumentsByTag,
useAllPrismicDocumentsByTags,
useAllPrismicDocumentsByType,
useAllPrismicDocumentsByUIDs,
useFirstPrismicDocument,
usePrismicDocumentByID,
usePrismicDocumentByUID,
Expand All @@ -44,6 +45,7 @@ export {
usePrismicDocumentsByTag,
usePrismicDocumentsByTags,
usePrismicDocumentsByType,
usePrismicDocumentsByUIDs,
useSinglePrismicDocument,
} from "./hooks";

Expand Down

0 comments on commit 3a25db8

Please sign in to comment.