Complete the code to register a new block in Gutenberg.
registerBlockType('myplugin/my-block', { title: 'My Block', category: [1] });
The category property defines where the block appears in the block inserter. 'common' is a standard category for general blocks.
Complete the code to create a block edit function that returns a paragraph block.
const Edit = () => { return <p>[1]</p>; };The edit function returns JSX that renders the block content in the editor. 'Hello World!' is a common placeholder text.
Fix the error in the block save function to correctly save a heading block.
const save = () => { return <h2>[1]</h2>; };The save function must return JSX with text inside quotes for string literals. Using quotes correctly ensures valid JSX.
Fill both blanks to correctly import and use the RichText component in a block edit function.
import { [1] } from '@wordpress/block-editor'; const Edit = () => { return <[2] tagName="p" value="Editable text" />; };
The RichText component is imported and used to create editable rich text in blocks. Both import and usage must match.
Fill all three blanks to correctly register a block with attributes and save function using RichText.
registerBlockType('myplugin/my-richtext-block', { attributes: { content: { type: [1] } }, edit: ({ attributes, setAttributes }) => { return <RichText tagName="p" value={attributes.content} onChange={content => setAttributes({ content })} />; }, save: ({ attributes }) => { return <RichText.Content tagName="p" value={attributes.[2] />; } });
The attribute type for text content is 'string'. The save function uses the attribute name 'content'. The value prop in RichText.Content should be the attribute value.