prismicio / prismic-react

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

feat: add `resolver` prop to SliceZone for backwards compatibility with `next-slicezone` #103

Closed angeloashmore closed 2 years ago

angeloashmore commented 2 years ago

Types of changes

Description

This PR adds a resolver prop that matches that of next-slicezone. This change makes the migration path smoother for users upgrading existing projects.

It is marked as deprecated in favor of the components prop. @prismicio/react's <SliceZone> will ultimately replace next-slicezone.

In a future major version, the resolver prop will be removed.

For reference, this is the type signature of the resolver function:

/**
 * Arguments for a `<SliceZone>` `resolver` function.
 */
type SliceZoneResolverArgs<TSlice extends SliceLike = SliceLike> = {
    /**
     * The Slice to resolve to a React component.
     */
    slice: TSlice;

    /**
     * The name of the Slice.
     */
    sliceName: TSlice["slice_type"];

    /**
     * The index of the Slice in the Slice Zone.
     */
    i: number;
};

/**
 * A function that determines the rendered React component for each Slice in the
 * Slice Zone.
 *
 * @deprecated Use the `components` prop instead.
 *
 * @param args - Arguments for the resolver function.
 *
 * @returns The React component to render for a Slice.
 */
export type SliceZoneResolver<
    TSlice extends SliceLike = SliceLike,
    TContext = unknown,
> = (
    args: SliceZoneResolverArgs<TSlice>,
) => SliceComponentType<TSlice, TContext>;

Checklist:

🦊