What is the correct way to use Fragments with create-block
Question
Within my custom block plugin, I am using create-block to generate my block environment for block editing. Within my `src/edit.js file I have the following setup…
import { __ } from 'wordpress user/i18n';
import {
useBlockProps,
Fragment,
RichText,
BlockControls,
} from 'wordpress user/block-editor';
import './editor.scss';
export default function Edit( { attributes, setAttributes } ) {
const { text } = attributes;
// additional options for our RichText component - https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/rich-text/README.md
return (
<Fragment>
<BlockControls controls={[{
title: "Button 1",
icon: "admin-generic",
onClick : () => console.log("Button 1 clicked!"),
},]} />
<RichText
{ ...useBlockProps() }
onChange={ ( value ) => setAttributes( { text: value } ) }
value={ text }
placeholder={ __( 'My chocolate placeholder', 'chocolate' ) }
tagName="h4"
allowedFormats={ 'core/bold' }
/>
</Fragment>
);
}
…But when I run npm start, and go to my edit page, I get the following error in the console…
Block validation: Block validation failed for `course-blocks/chocolate` ( ....}
What is the recommended approach to using fragments with create-block?
0
1 week
2023-03-14T10:59:33-05:00
2023-03-14T10:59:33-05:00 0 Answers
0 views
0
Leave an answer