【问题标题】:gutenberg blockListBlock filter block control renders multiple timesgutenberg blockListBlock 过滤器块控件呈现多次
【发布时间】:2022-01-05 17:17:36
【问题描述】:

我不知道为什么 Gutenberg 将我添加的 BlockControl 渲染 3 次,并且还渲染到其他不是“核心/段落”的组件。 我的代码:

const filter_text_highlight_color = createHigherOrderComponent( (BlockListBlock) => {
    return (props) => {

            if (props.name === 'core/paragraph') {

                const startEditing = () => {
                    console.log('hello!');
                }

                return ([
                
                    
                    <BlockListBlock {...props} />,
                    <BlockControls>
                        <ToolbarButton
                            name="link"
                            icon="text-page"
                            title={ __('Highlight Text') }
                            onClick={ startEditing }
                        />
                    </BlockControls>,
                  
                  
                ])

            } else {

                return (
                    <BlockListBlock {...props} />
                )
            }
    }
}, 'filter_text_highlight_color'
); 

addFilter(
    'editor.BlockListBlock',
    'bwwpcode/text-highlight-color',
    filter_text_highlight_color,
)

我将不胜感激任何关于为什么会发生这种情况以及如何解决它的建议。

【问题讨论】:

    标签: wordpress filter block wordpress-gutenberg


    【解决方案1】:

    我想通了! BlockListBlock 只能用于向块添加控件。该过滤器的工作方式与 BlockEdit 过滤器完全不同。

    更改为 BlockEdit 过滤器后一切正常!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-11
      • 2019-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多