With an attribute in block.json as attributes: { foo: { type: string, default: bar } }
In edit.js :
import { useBlockProps, RichText } from '@wordpress/block-editor';
export default function Edit( { attributes, setAttributes } ) {
const blockProps = useBlockProps();
return (
<RichText
{ ...useBlockProps() }
tagName="p"
onChange={ val => setAttributes( { foo: val } ) }
value={ attributes.content }
placeholder="Enter some text here..."
/>
);
}
In render.php
echo attributes['foo'];
Sources: