Title: wp.data.dispatch( &#8216;core&#8217; ) returns null
Last modified: February 11, 2024

---

# wp.data.dispatch( ‘core’ ) returns null

 *  Resolved [lewiswharf](https://wordpress.org/support/users/accescape/)
 * (@accescape)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/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@latest`
   command.
 * 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.js` file with the code I have added starting at `
   import { dispatch } from '@wordpress/data';` (scaffold comments removed for brevity).
 *     ```wp-block-code
       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' )` returns `null` and I have no idea why. Should
   I be calling it in a different place?
    -  This topic was modified 2 years, 4 months ago by [lewiswharf](https://wordpress.org/support/users/accescape/).
    -  This topic was modified 2 years, 4 months ago by [lewiswharf](https://wordpress.org/support/users/accescape/).
      Reason: code formatting

Viewing 1 replies (of 1 total)

 *  Thread Starter [lewiswharf](https://wordpress.org/support/users/accescape/)
 * (@accescape)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/wp-data-dispatch-core-returns-null/#post-17416490)
 * Ah, need to put dispatch code in a hook…
 *     ```wp-block-code
       import { dispatch } from '@wordpress/data';
       import { addAction } from '@wordpress/hooks';
   
       addAction('plugins.pluginRegistered', 'amilia/register-programs-entity', (() => {
       	dispatch( 'core' ).addEntities( [
       		{
       			name: 'program',
       			kind: 'amilia',
       			baseURL: '/amilia/v1/programs',
   
       		},
       	] );
       }));
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘wp.data.dispatch( ‘core’ ) returns null’ is closed to new replies.

## Tags

 * [block](https://wordpress.org/support/topic-tag/block/)
 * [gutenberg](https://wordpress.org/support/topic-tag/gutenberg/)
 * [plugin](https://wordpress.org/support/topic-tag/plugin/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 1 participant
 * Last reply from: [lewiswharf](https://wordpress.org/support/users/accescape/)
 * Last activity: [2 years, 4 months ago](https://wordpress.org/support/topic/wp-data-dispatch-core-returns-null/#post-17416490)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
