admin管理员组文章数量:1208155
I have the @wordpress/data
package installed, but I can't use useDispatch
in my block edit function:
const { registerBlockType } = wp.blocks;
const { useDispatch, useSelect } = wp.data;
.
.
.
registerBlockType( 'rb-bootstrap/grid', {
...
edit: function( props ) {
const { replaceInnerBlocks } = useDispatch("core/block-editor");
}
}
TypeError: useDispatch is not a function
What am I missing?
I have the @wordpress/data
package installed, but I can't use useDispatch
in my block edit function:
const { registerBlockType } = wp.blocks;
const { useDispatch, useSelect } = wp.data;
.
.
.
registerBlockType( 'rb-bootstrap/grid', {
...
edit: function( props ) {
const { replaceInnerBlocks } = useDispatch("core/block-editor");
}
}
TypeError: useDispatch is not a function
What am I missing?
Share Improve this question asked Oct 23, 2019 at 4:38 RabaRaba 4062 silver badges12 bronze badges 2 |2 Answers
Reset to default 0I used to have the same problem. After I updated Wordpress, window.wp.data.useDispatch was available.
I'm guessing you also have an out of date Wordpress / Gutenberg
Stuff like wp.data.useDispatch
and wp.data.useSelect
were implemented in WP 5.3 (released on November 12, 2019). In older versions those are not available and you are supposed to use compose
. This article details how it was on 5.2 and before, and how it is now (much cleaner code).
本文标签: plugin developmentGutenberg useDispatch is not a functionwordpressdata included
版权声明:本文标题:plugin development - Gutenberg: useDispatch is not a function - @wordpressdata included 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738747064a2110182.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
useSelect
. Are you usingcreate-guten-block
as well? – Claudio Cortese Commented Oct 24, 2019 at 19:38