prismicio / prismic-react

React components and hooks to fetch and present Prismic content
https://prismic.io/docs/technologies/homepage-reactjs
Apache License 2.0
153 stars 40 forks source link

fix(`usePrismicClient()`): accept a type parameter to define which documents are supported by the client (e.g. `Content.AllDocumentTypes`) #197

Closed angeloashmore closed 8 months ago

angeloashmore commented 8 months ago

Types of changes

Description

This PR fixes a bug/limitation in usePrismicClient() that did not allow the Prismic client to use content types generated by prismic-ts-codegen or Slice Machine.

As of this PR, you can now provide usePrismicClient() with a type parameter specifying the content types, just like using @prismicio/client's createClient() function directly.

import type { Content } from "@prismicio/client";
import { usePrismicClient } from "@prismicio/react";

// To provide content types:
const client = usePrismicClient<Content.AllDocumentTypes>();

// A generic client is still supported by not passing a type parameter:
const client = usePrismicClient();

Checklist:

codecov-commenter commented 8 months ago

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (ca3f851) 99.68% compared to head (39100db) 99.68%.

:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the GitHub App Integration for your organization. Read more.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #197 +/- ## ======================================= Coverage 99.68% 99.68% ======================================= Files 20 20 Lines 2561 2563 +2 Branches 95 95 ======================================= + Hits 2553 2555 +2 Misses 8 8 ``` | [Files Changed](https://app.codecov.io/gh/prismicio/prismic-react/pull/197?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=prismicio) | Coverage Δ | | |---|---|---| | [src/usePrismicClient.ts](https://app.codecov.io/gh/prismicio/prismic-react/pull/197?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=prismicio#diff-c3JjL3VzZVByaXNtaWNDbGllbnQudHM=) | `100.00% <100.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

github-actions[bot] commented 8 months ago

size-limit report 📦

Path Size
./dist/index.cjs 8.02 KB (0%)
./dist/index.js 6.05 KB (0%)
./dist/react-server.cjs 7.21 KB (0%)
./dist/react-server.js 5.57 KB (0%)