Created
October 9, 2021 02:26
-
-
Save devmnj/dcd3cf22ab4df25f2df51b35016a212a to your computer and use it in GitHub Desktop.
Prismic - React slice rendering component
This file contains hidden or 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
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