I'm using Gutenberg block filters to add a class name to the block’s wrapper component in the editor.
registerBlockType( name, {
title: __( 'My Block' ),
parent: [ 'myplugin/myblock' ],
category: 'common',
attributes: attributes,
edit( { attributes, setAttributes, className } ) {
const { someName } = attributes;
return (
/* render something */
);
},
save( { attributes } ) {
const { someName } = attributes;
return (
/* render something */
);
},
});
const customClassName = createHigherOrderComponent( ( BlockListBlock ) => {
return ( props ) => {
return <BlockListBlock { ...props } className={ someName } />;
};
}, 'customClassName' );
wp.hooks.addFilter( 'editor.BlockListBlock', 'myplugin/myblock', customClassName );
How can I pass someName
from my block attributes to the customClassName
filter? Adding constant customClassName
and wp.hooks.addFilter()
in the edit function does not seem to work well because it causes repeatable filtering/rendering.