You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously with @sanity/block-content-to-react you could use children in your custom blocks component:
importBaseBlockContentfrom'@sanity/block-content-to-react';constcomponents={types: {block(props){const{ children }=props;return<div>{children}</div>;}},};functionMyPage(props){return(<BaseBlockContentcomponents={components}/>);}
Now with this package the attribute is no longer available in props. This is the code I'm using to compute it myself as a workaround, which hopefully helps someone else.
import{PortableText}from'@portabletext/react';import{buildMarksTree}from'@portabletext/toolkit';constcomponents={types: {block(props){const{ value, renderNode }=props;constchildren=buildMarksTree(value).map((child,i)=>(renderNode({node: child,isInline: true,index: i,
renderNode,})));return<div>{children}</div>;}}};functionMyPage(props){return(<PortableTextcomponents={components}/>);}
The text was updated successfully, but these errors were encountered:
gmferise
changed the title
Undocumented breaking change for Sanity migration
Children prop no longer available in custom block content
Jan 19, 2024
Previously with
@sanity/block-content-to-react
you could usechildren
in your customblocks
component:Now with this package the attribute is no longer available in props. This is the code I'm using to compute it myself as a workaround, which hopefully helps someone else.
The text was updated successfully, but these errors were encountered: