Skip to content

Instantly share code, notes, and snippets.

@onefriendaday
Created March 20, 2020 11:36
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 onefriendaday/3720e40bd314c0a867719c314d02fd19 to your computer and use it in GitHub Desktop.
Save onefriendaday/3720e40bd314c0a867719c314d02fd19 to your computer and use it in GitHub Desktop.
const StoryblokClient = require('storyblok-js-client')
const Storyblok = new StoryblokClient({
accessToken: 'YOUR_TOKEN'
})
Storyblok.setComponentResolver((component, blok) => {
switch(component) {
case 'my_button':
return `<button>${blok.button_text}</button>`
break;
case 'contact_form':
return `<a href="mailto:${blok.mail}">Mail me at: ${blok.mail}</a>`
break;
}
})
function createMarkup(storyblokHTML) {
return {
__html: Storyblok.richTextResolver.render(storyblokHTML),
}
}
const RichTextField = ({ data }) => {
return <div dangerouslySetInnerHTML={createMarkup(data)} />
}
export default RichTextField
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment