admin管理员组文章数量:1130349
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.
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.
本文标签: block editorGutenberg pass properties to filter
版权声明:本文标题:block editor - Gutenberg pass properties to filter 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749035788a2306371.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论