I'm creating a block and using rich text to save some text this is my edit function.
edit: (props) => {
const { attributes: { content, backgroundImage }, setAttributes } = props;
const onImageSelect = (imageObject) => {
setAttributes({ backgroundImage: imageObject.sizes.full.url });
}
const onChangeContent = (newContent) => {
setAttributes({ content: newContent });
};
console.log(content);
return (
<div className={props.className}>
<MediaUpload
onSelect={onImageSelect}
type="image"
value={backgroundImage}
render={({ open }) => (
<button onClick={open}>
Upload Image!
</button>
)}
/>
<img src={backgroundImage} alt="eherh" />
<div className={'caption'}>
<RichText
tagName={"p"}
className={'imgCtaContent'}
onChange={onChangeContent}
value={content}
placeholder="Enter text..."
/>
</div>
</div>
);
},
and this is my save function: -
save: (props) => {
return (
<div className={props.className}>
<RichText.Content tagName={"p"} value={props.attributes.content} />
</div>
);
},
I can see when I type into the block when I'm editing it that the console.log(content) displays the content but when I save the page the text isn't saved.
Where am I going wrong?