Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RichText Component
const { registerBlockType } = wp.blocks;
const { RichText } = wp.editor;
const result = registerBlockType( 'myguten-block/test-block', {
title: 'Basic Example',
icon: 'smiley',
category: 'layout',
attributes: {
content: {
type: 'array',
source: 'children',
selector: 'p',
},
},
edit: ( props ) => {
console.log( props );
const { attributes: { content }, setAttributes, className } = props;
const onChangeContent = ( newContent ) => {
setAttributes( { content: newContent } );
};
return (
<RichText
tagName="p"
className={ className }
onChange={ onChangeContent }
value={ content }
/>
);
},
save: ( props ) => {
return <RichText.Content tagName="p" value={ props.attributes.content } />;
},
} );
console.log( result );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment