Created
March 20, 2020 11:36
-
-
Save onefriendaday/3720e40bd314c0a867719c314d02fd19 to your computer and use it in GitHub Desktop.
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
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