strapi / blocks-react-renderer

A React renderer for the Strapi's Blocks rich text editor
Other
141 stars 23 forks source link

[bug]: block of list type returning children as string instead of array #36

Closed pappitito closed 4 months ago

pappitito commented 4 months ago

What version of @strapi/blocks-react-renderer are you using?

-npm: 9.8.1 - node 18.18.0 - "@strapi/blocks-react-renderer": "^1.0.1"

What's Wrong?

given i want to customize a block with type list and i add the return function with destructured parameter being "children" and "format". i am unable to return a node where the children are being mapped, says i cannot map children of type string.

To Reproduce

<BlocksRenderer content={content} blocks={{ list : ({format, children, })=>{ if(format === 'ordered'){ //line below returns error saying i cannot map children because it is of type string return

{ children.map((item, index)=>(
  • {item}
  • )) }
    } } }} />

    Expected Behaviour

    i should be able to map children

    remidej commented 4 months ago

    Hello, I don't think this is a bug. list blocks aren't meant to have access to the list items directly, they should just render the shell of the shell of the list. The content is then displayed by the list-item blocks.

    You can see what it looks like with the default components:

    {
      list: (props) => {
        if (props.format === 'ordered') {
          return <ol>{props.children}</ol>;
        }
    
        return <ul>{props.children}</ul>;
      },
      'list-item': (props) => <li>{props.children}</li>,
    }