Gutenberg: useDispatch is not a function – @wordpress/data included

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?

2 Answers
2

I 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

Leave a Comment