Skip to content

Instantly share code, notes, and snippets.

@devmnj
Created October 9, 2021 02:26
Show Gist options
  • Save devmnj/dcd3cf22ab4df25f2df51b35016a212a to your computer and use it in GitHub Desktop.
Save devmnj/dcd3cf22ab4df25f2df51b35016a212a to your computer and use it in GitHub Desktop.
Prismic - React slice rendering component
class Slices extends React.Component {
render() {
if (this.props.slices) {
const pageContent = this.props.slices.map((slice, index) => {
if (slice.slice_type === "heading_slice") {
console.log('heading');
return (
<div className="font-bold text-2xl ">
{RichText.render(slice.primary.header_rich_text_field)}
</div>
);
} else if (slice.slice_type === "paragraph_slice") {
return (
<div className="text-justify text-2xl">
{RichText.render(slice.primary.paragraph_rich_text_field,linkResolver)}
</div>
);
} else if (slice.slice_type === "code_slice"){
return (
<div className="relative">
<Snippet code={RichText.asText(slice.primary.cod_text_field)} />
</div>
);
}
});
return pageContent
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment