Last active
March 19, 2024 12:54
-
-
Save SimeonGriggs/ee5b1d606f176d6e9305963ad548c99e to your computer and use it in GitHub Desktop.
Rendering blocks from a "page builder" array in Sanity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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