Skip to content

Instantly share code, notes, and snippets.

@kellenmace
Created August 31, 2021 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kellenmace/63467ce0c7a3629f4a457766640527ca to your computer and use it in GitHub Desktop.
Save kellenmace/63467ce0c7a3629f4a457766640527ca to your computer and use it in GitHub Desktop.
Gutenberg Block Component Mapping
const componentMap = {
'core/quote': QuoteBlock,
'core/pullquote': PullquoteBlock,
'core/code': CodeBlock,
'core/preformatted': PreformattedBlock,
'core/embed': EmbedBlock,
'core/media-text': MediaTextBlock,
'core/button': ButtonBlock,
'core/buttons': ButtonsBlock,
'core/columns': ColumnsBlock,
'core/cover': CoverBlock,
'core/heading': HeadingBlock,
'core/image': ImageBlock,
'core/gallery': GalleryBlock,
'core/table': TableBlock,
'core/list': ListBlock,
'core/paragraph': ParagraphBlock,
'core/separator': SeparatorBlock,
'core/spacer': SpacerBlock,
};
export default function Block({ block }) {
const { attributes, name, innerBlocks } = block;
const BlockComponent = componentMap[name];
if (!BlockComponent) {
return null;
}
if (innerBlocks) {
return <BlockComponent attributes={attributes} innerBlocks={innerBlocks} />;
}
return <BlockComponent {...attributes} />;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment