Skip to content

Commit

Permalink
fix: more specific SliceZone types
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloashmore committed Jul 2, 2021
1 parent ec80b33 commit a4d5a2d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/SliceZone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ export type SliceZoneProps<TSlice extends SliceLike, TContext> = {

/** A record mapping Slice types to React components. */
components: Partial<
Record<TSlice["slice_type"], React.ComponentType<SliceComponentProps>>
Record<
TSlice["slice_type"],
React.ComponentType<SliceComponentProps<TSlice, TContext>>
>
>;

/** The React component rendered if a component mapping from the `components` prop cannot be found. */
Expand Down Expand Up @@ -107,9 +110,10 @@ export const SliceZone = <TSlice extends SliceLike, TContext>({
}: SliceZoneProps<TSlice, TContext>): JSX.Element => {
const renderedSlices = React.useMemo(() => {
return slices.map((slice, index) => {
const Comp: React.ComponentType<SliceComponentProps> =
components[slice.slice_type as keyof typeof components] ||
defaultComponent;
const Comp = (components[slice.slice_type as keyof typeof components] ||
defaultComponent) as React.ComponentType<
SliceComponentProps<TSlice, TContext>
>;
const key = JSON.stringify(slice);

return (
Expand Down

0 comments on commit a4d5a2d

Please sign in to comment.