Skip to content

Instantly share code, notes, and snippets.

@SimeonGriggs
Last active March 19, 2024 12:54
Show Gist options
  • Save SimeonGriggs/ee5b1d606f176d6e9305963ad548c99e to your computer and use it in GitHub Desktop.
Save SimeonGriggs/ee5b1d606f176d6e9305963ad548c99e to your computer and use it in GitHub Desktop.
Rendering blocks from a "page builder" array in Sanity
import type { KeyedObject, TypedObject } from "sanity";
import PageBuilderContent from "./pageBuilderContent";
import PageBuilderColumns from "./pageBuilderColumns";
const Components = {
pageBuilderContent: PageBuilderContent,
pageBuilderColumns: PageBuilderColumns,
};
export function PageBuilder({
blocks,
}: {
blocks: (TypedObject & KeyedObject)[];
}) {
return pageBuilder.map((block, index) =>
Components[block._type]
? React.createElement(Components[block._type], {
key: block._key,
...block,
})
: null,
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment