wp.data.dispatch( ‘core’ ) returns null
-
I am following the tutorial “Build your first block” and have a folder structure representing the scaffold created by the
npx @wordpress/create-block@latestcommand.Using it as my starting point, I’m trying to retrieve the WordPress core store to add an entity, but I keep getting the error “Uncaught TypeError: Cannot read properties of null (reading ‘addEntities’)”.
Here is the whole
src/index.jsfile with the code I have added starting atimport { dispatch } from '@wordpress/data';(scaffold comments removed for brevity).import { registerBlockType } from '@wordpress/blocks'; import './style.scss'; import Edit from './edit'; import metadata from './block.json'; registerBlockType( metadata.name, { /** * @see ./edit.js */ edit: Edit, } ); import { dispatch } from '@wordpress/data'; dispatch( 'core' ).addEntities( [ { name: 'programs', kind: 'amilia/v1', baseURL: 'amilia/v1/programs', }, ] );It appears
dispatch( 'core' )returnsnulland I have no idea why. Should I be calling it in a different place?
The topic ‘wp.data.dispatch( ‘core’ ) returns null’ is closed to new replies.