Repository navigation
Replies: 1 comment
|
Rendering Slate JSON as React elements is a reasonable serialization approach. The maintenance issue in your example is that the leaf renderer is repeated in each heading/paragraph, while list items only output function StyledLeaf({ leaf }) {
const decoration = [
leaf.underline && 'underline',
leaf.strikethrough && 'line-through',
].filter(Boolean).join(' ') || 'none';
return <span style={{
fontWeight: leaf.bold ? 'bold' : 'normal',
fontStyle: leaf.italic ? 'italic' : 'normal',
textDecoration: decoration,
}}>{leaf.text}</span>;
}This also represents underline and strikethrough together through one property, rather than setting both React renders |
Uh oh!
There was an error while loading. Please reload this page.
I was trying to see if this approach works or not and I get the desired output but again this is just a test.
Is this a bad approach if I consider maintainability or browser compatibility ?
All reactions