Skip to content

Commit

Permalink
feat: support slice id
Browse files Browse the repository at this point in the history
  • Loading branch information
lihbr committed Jul 28, 2022
1 parent 5be1649 commit d066399
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 11 deletions.
80 changes: 73 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"lint": "eslint --ext .js,.jsx,.ts,.tsx .",
"prepare": "npm run build",
"release": "npm run build && npm run test && standard-version && git push --follow-tags && npm run build && npm publish",
"release:beta": "npm run build && npm run test && standard-version --release-as major --prerelease beta && git push --follow-tags && npm run build && npm publish --tag beta",
"release:beta:dry": "standard-version --release-as major --prerelease beta --dry-run",
"release:alpha": "npm run build && npm run test && standard-version --release-as minor --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha",
"release:alpha:dry": "standard-version --release-as minor --prerelease alpha --dry-run",
"release:dry": "standard-version --dry-run",
"size": "size-limit",
"test": "npm run lint && npm run unit && npm run build && npm run size",
Expand All @@ -52,7 +52,7 @@
"devDependencies": {
"@prismicio/client": "^6.4.2",
"@prismicio/mock": "^0.0.10",
"@prismicio/types": "^0.1.27",
"@prismicio/types": "^0.2.1-alpha",
"@size-limit/preset-small-lib": "^7.0.8",
"@testing-library/react": "^12.1.4",
"@testing-library/react-hooks": "^7.0.2",
Expand Down
6 changes: 5 additions & 1 deletion src/SliceZone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type ExtractSliceType<Slice extends SliceLike> = Slice extends SliceLikeRestV2
*/
export type SliceLikeRestV2<SliceType extends string = string> = {
slice_type: prismicT.Slice<SliceType>["slice_type"];
slice_id?: string;
};

/**
Expand Down Expand Up @@ -304,7 +305,10 @@ export const SliceZone = <TContext,>({
}
}

const key = `${index}-${JSON.stringify(slice)}`;
const key =
"slice_id" in slice && slice.slice_id
? slice.slice_id
: `${index}-${JSON.stringify(slice)}`;

return (
<Comp
Expand Down

0 comments on commit d066399

Please sign in to comment.