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

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

Merged
merged 2 commits into from Nov 22, 2021

Conversation

angeloashmore
Copy link
Member

@angeloashmore angeloashmore commented Nov 22, 2021

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 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:

  • 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.

🦊

@angeloashmore angeloashmore changed the title feat: add resolver prop to SliceZone for backwards compatibility with next-slicezone feat: add resolver prop to SliceZone for backwards compatibility with next-slicezone Nov 22, 2021
@angeloashmore angeloashmore merged commit cfdcfb1 into v2 Nov 22, 2021
@angeloashmore angeloashmore deleted the aa/slicezone-resolver branch November 22, 2021 19:56
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.

None yet

1 participant