claus / storyblok-rich-text-react-renderer

A React renderer for Storyblok rich text content
MIT License
86 stars 16 forks source link

Possible to use Default Blok resolver to add support for all bloks. #29

Closed sachahboun closed 1 year ago

sachahboun commented 1 year ago

Hi,

Type of issue: Suggestion to extend readme section on Default blok resolvers. Reason: Ability to Include support for all bloks without having to resolve each react component.

Description: I used this library for a project at work, but I did not want to add in resolvers for every single blok. So I tried playing around with the DefaultBlokResolver and the storyblokComponent provided by the storyblok library to automatically render all storyblok components used in a richtext field. The result is included below. It seems to do it's job.

Example:

    <div>
      {render(blok.richtext, {
        defaultBlokResolver: (name, props) => {
          const embeddedBlok = props;
          embeddedBlok.component = name;
          return <StoryblokComponent blok={embeddedBlok} key={props._uid} />;
        },
      })}
    </div>
claus commented 1 year ago

Added. Thank you!