在 gutenberg 编辑器中,我需要获取 BlockListBlock 元素的引用,但它似乎不起作用。有办法实现吗?
const withCustomAttribute = createHigherOrderComponent(
(BlockListBlock) => {
return (props) => {
const blockRef = createRef();
useEffect(() => {
console.log(blockRef); // => "{current: null}"
});
return <BlockListBlock {...props} ref={blockRef} />;
};
},
'withCustomAttribute'
);
addFilter(
'editor.BlockListBlock',
'example/custom-attribute',
withCustomAttribute
);
最佳答案
我不认为有一种简单的方法可以实现你想要的,因为<BlockListBlock />
不支持任何类型的 ref
通过。
可以看源码here .
关于reactjs - 在 block 编辑器中获取对 BlockListBlock 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70369563/