block editor - Gutenberg pass properties to filter

admin2025-06-04  44

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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749035812a315814.html

最新回复(0)