I'm tring to make dynamic custom block using "RichText" and wondering how to set it's attributes. By checking examples on the internet, some people set its attributes to "Array & Children" but I also found the examples with "HTML & Class Name".
I tried both patterns(Pattern A and B below) but their results on frontend are exactly the same. I'd like to know the difference between them and which is the better way.
Pattern A
attributes: {
message: {
type: 'array',
source: 'children',
selector: '.message',
}
},
Pattern B
attributes: {
message: {
type: 'string',
source: 'html',
selector: '.message',
}
},
edit & save functions
edit: props => {
const {attributes:{message}, className, setAttributes} = props;
const onChangeMessage = message => {
setAttributes({message});
}
return(
<div className={ className }>
<RichText
tagName = "div"
multiline = "p"
onChange = {onChangeMessage}
value = {message}
/>
</div>
);
},
save: props => {
const {attributes:{message}} = props;
return (
<div>
<div class="message">
<RichText.Content
value = {message}
/>
</div>
</div>
);
},