Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 31, 2023

Conversation

angeloashmore
Copy link
Member

@angeloashmore angeloashmore commented Aug 31, 2023

Types of changes

  • Chore (a non-breaking change which is related to package maintenance)
  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

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:

  • My change requires an update to the official documentation.
  • All TSDoc comments are up-to-date and new ones have been added where necessary.
  • All new and existing tests are passing.

…cuments are supported by the client (e.g. `Content.AllDocumentTypes`)
@codecov-commenter
Copy link

Codecov Report

Patch coverage: 100.00% and no project coverage change.

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

❗ 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
@@           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 Coverage Δ
src/usePrismicClient.ts 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions
Copy link

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%)

@angeloashmore angeloashmore merged commit b16e968 into master Aug 31, 2023
@angeloashmore angeloashmore deleted the aa/usePrismicClient-document-types branch August 31, 2023 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants