Skip to content

Commit

Permalink
fix: use React 18 and 19 compatible types (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloashmore authored Jan 29, 2025
1 parent 6d687fa commit 5c3bc34
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion examples/custom-slicezone-props/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ const components: Record<string, SliceComponentType> = {

// We render the Slice Zone using the `<SliceZone>` component by passing the
// list of Slices and component map.
export const App = (): JSX.Element => {
export const App = (): React.JSX.Element => {
return <SliceZone slices={slices} components={components} />;
};
2 changes: 1 addition & 1 deletion examples/router-link/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const LinkShim = ({ href, ...props }: LinkProps) => {

// We render the Link field using `<PrismicLink>`. Since the field contains an
// internal URL, react-router-dom's `<Link>` component will render.
export const App = (): JSX.Element => {
export const App = (): React.JSX.Element => {
return (
<main>
<PrismicLink field={field} internalComponent={LinkShim} />
Expand Down
2 changes: 1 addition & 1 deletion examples/with-global-configuration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const MyComponent = () => {
// `<PrismicProvider>`. We pass global Prismic configuration to the provider at
// this level. By doing so, it becomes available automatically to all Prismic
// components lower in the tree.
export const App = (): JSX.Element => {
export const App = (): React.JSX.Element => {
return (
<PrismicProvider
internalLinkComponent={LinkShim}
Expand Down
8 changes: 4 additions & 4 deletions examples/with-typescript/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ declare const page: PageDocument;
// correct fields are passed.

// Rendering a Rich Text or Title looks like this.
export const WithRichText = (): JSX.Element => {
export const WithRichText = (): React.JSX.Element => {
return <PrismicRichText field={page.data.title} />;
};

// Rendering a link to a document looks like this.
export const WithDocumentLink = (): JSX.Element => {
export const WithDocumentLink = (): React.JSX.Element => {
return <PrismicLink document={page} />;
};

// Rendering a group looks like this.
// Using `isFilled.group()` and `isFilled.link()` from `@prismicio/helpers`
// checks if the fields have a value.
export const WithGroupFieldLink = (): JSX.Element => {
export const WithGroupFieldLink = (): React.JSX.Element => {
return (
<ul>
{prismic.isFilled.group(page.data.related_links) &&
Expand All @@ -93,7 +93,7 @@ export const WithGroupFieldLink = (): JSX.Element => {
// Rendering a Slice Zone looks like this.
// Note that the `components` object is typed to ensure a component is given
// for each Slice type.
export const WithSliceZone = (): JSX.Element => {
export const WithSliceZone = (): React.JSX.Element => {
return (
<SliceZone
slices={page.data.slices}
Expand Down
2 changes: 1 addition & 1 deletion src/PrismicImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const PrismicImage = React.forwardRef(function PrismicImage(
...restProps
}: PrismicImageProps,
ref: React.ForwardedRef<HTMLImageElement>,
): JSX.Element | null {
): React.JSX.Element | null {
if (
typeof process !== "undefined" &&
process.env.NODE_ENV === "development"
Expand Down
2 changes: 1 addition & 1 deletion src/PrismicLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ export const PrismicLink = React.forwardRef(function PrismicLink<
props: PrismicLinkProps<InternalComponentProps, ExternalComponentProps> & {
ref?: React.ForwardedRef<Element>;
},
) => JSX.Element;
) => React.JSX.Element;
2 changes: 1 addition & 1 deletion src/PrismicProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const PrismicProvider = <
internalLinkComponent,
externalLinkComponent,
children,
}: PrismicProviderProps<LinkResolverFunction>): JSX.Element => {
}: PrismicProviderProps<LinkResolverFunction>): React.JSX.Element => {
const value = React.useMemo<PrismicContextValue<LinkResolverFunction>>(
() => ({
client,
Expand Down
4 changes: 3 additions & 1 deletion src/PrismicText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export type PrismicTextProps = {
*
* @see Learn about Rich Text fields {@link https://prismic.io/docs/core-concepts/rich-text-title}
*/
export const PrismicText = (props: PrismicTextProps): JSX.Element | null => {
export const PrismicText = (
props: PrismicTextProps,
): React.JSX.Element | null => {
if (
typeof process !== "undefined" &&
process.env.NODE_ENV === "development"
Expand Down
2 changes: 1 addition & 1 deletion src/SliceZone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export const TODOSliceComponent = <TSlice extends SliceLike>({
slice,
}: {
slice: TSlice;
}): JSX.Element | null => {
}): React.JSX.Element | null => {
if (
typeof process !== "undefined" &&
process.env.NODE_ENV === "development"
Expand Down
4 changes: 2 additions & 2 deletions src/react-server/PrismicLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const PrismicLink = React.forwardRef(function PrismicLink<
>(
props: PrismicLinkProps<InternalComponentProps, ExternalComponentProps>,
ref: React.ForwardedRef<Element>,
): JSX.Element {
): React.JSX.Element {
const {
field,
document: doc,
Expand Down Expand Up @@ -194,4 +194,4 @@ export const PrismicLink = React.forwardRef(function PrismicLink<
props: PrismicLinkProps<InternalComponentProps, ExternalComponentProps> & {
ref?: React.ForwardedRef<Element>;
},
) => JSX.Element;
) => React.JSX.Element;
4 changes: 2 additions & 2 deletions src/react-server/PrismicRichText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export function PrismicRichText<
externalLinkComponent,
internalLinkComponent,
...restProps
}: PrismicRichTextProps<LinkResolverFunction>): JSX.Element | null {
}: PrismicRichTextProps<LinkResolverFunction>): React.JSX.Element | null {
return React.useMemo(() => {
if (
typeof process !== "undefined" &&
Expand Down Expand Up @@ -298,7 +298,7 @@ export function PrismicRichText<
// The serializer is wrapped in a higher-order function
// that automatically applies a key to React Elements
// if one is not already given.
const serialized = prismicR.serialize<JSX.Element>(
const serialized = prismicR.serialize<React.JSX.Element>(
field,
(type, node, text, children, key) => {
const result = serializer(type, node, text, children, key);
Expand Down
2 changes: 1 addition & 1 deletion src/react-server/unsupported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function buildIncompatibleQueryHookInServerComponentsErrorMessage(
return `${fnName} is not supported in Server Components. Replace ${fnName} in Server Components with direct use of \`@prismicio/client\` (recommended) or add the "use client" directive to the component using the hook.`;
}

export function PrismicProvider(): JSX.Element {
export function PrismicProvider(): React.JSX.Element {
throw new Error(
buildIncompatibleInServerComponentsErrorMessage("<PrismicProvider>"),
);
Expand Down
5 changes: 3 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import * as prismicR from "@prismicio/richtext";
* @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}
*/
export type JSXFunctionSerializer =
prismicR.RichTextFunctionSerializer<JSX.Element>;
prismicR.RichTextFunctionSerializer<React.JSX.Element>;

/**
* A map of Rich Text block types to React Components. It is used to render Rich
* Text or Title fields.
*
* @see Templating Rich Text and Title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}
*/
export type JSXMapSerializer = prismicR.RichTextMapSerializer<JSX.Element>;
export type JSXMapSerializer =
prismicR.RichTextMapSerializer<React.JSX.Element>;

/**
* States of a `@prismicio/client` hook.
Expand Down
2 changes: 1 addition & 1 deletion test/SliceZone.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const StringifySliceComponent = ({
slices,
context,
...restProps
}: StringifySliceComponentProps): JSX.Element => (
}: StringifySliceComponentProps): React.JSX.Element => (
<div data-id={id}>
<div data-slice={JSON.stringify(slice)} />
<div data-index={index} />
Expand Down

0 comments on commit 5c3bc34

Please sign in to comment.