Closed maurocolella closed 3 years ago
Hey @maurocolella! Our friend @claus already did that :) https://github.com/claus/storyblok-rich-text-react-renderer Hope that helps! :)
import { render } from 'storyblok-rich-text-react-renderer';
function RichText({ document }) {
// document is the rich text object you receive from Storyblok,
// in the form { type: "doc", content: [ ... ] }
return <div>{render(document)}</div>;
}
It also supports custom components: https://github.com/claus/storyblok-rich-text-react-renderer#blok-resolvers
Hey @DominikAngerer thanks! That looks like it might help.
By the way, loving Storyblok so far.
Hello again. With version
^3.3.0
, the rich text resolver returns a string.In React, as far as I can tell this means I need to use
dangerouslySetInnerHTML
to render the result as HTML.If I try to use
React.createElement
, an error is produced. This is non-critical at the moment, but I would like to suggest creating a wrapper that is react-only, ie.storyblok-react-js-client
, and handles this specific edge case by returning React nodes.The reason for this is that I suspect it might otherwise become cumbersome to render nested blocks.