Title: Changes in @wordpress/data API
Author: Robert Anderson
Published: February 22, 2021

---

 [  ](https://profiles.wordpress.org/noisysocks/) [Robert Anderson](https://profiles.wordpress.org/noisysocks/)
11:50 pm _on_ February 22, 2021     
Tags: [5.7 ( 67 )](https://make.wordpress.org/core/tag/5-7/),
[block-editor ( 137 )](https://make.wordpress.org/core/tag/block-editor/), [dev-notes ( 621 )](https://make.wordpress.org/core/tag/dev-notes/)

# Changes in @wordpress/data API

As of [#26655](https://github.com/WordPress/gutenberg/pull/26655), it is now possible
to pass a store definition instead of the string when referencing a given store 
registered with `@wordpress/data` APIAPI An API or Application Programming Interface
is a software intermediary that allows programs to interact with each other and 
share data in limited, clearly defined ways.. This change impacts mostly the GutenbergGutenberg
The Gutenberg project is the new Editor Interface for WordPress. The editor improves
the process and experience of creating new content, making writing rich content 
much simpler. It uses ‘blocks’ to add richness rather than shortcodes, custom HTML
etc. [https://wordpress.org/gutenberg/](https://wordpress.org/gutenberg/) project.
It is fully backward compatible, so pluginPlugin A plugin is a piece of software
containing a group of functions that can be added to a WordPress website. They can
extend functionality or add new features to your WordPress websites. WordPress plugins
are written in the PHP programming language and integrate seamlessly with WordPress.
These can be free in the WordPress.org Plugin Directory [https://wordpress.org/plugins/](https://wordpress.org/plugins/)
or can be cost-based plugin from a third-party. and theme authors can continue using
hardcoded names when referencing data stores.

The store registration has now two new methods [`register`](https://github.com/WordPress/gutenberg/blob/master/packages/data/README.md#register)
that takes the store definition as a param to register a store. There is also a 
new helper method [`createReduxStore`](https://github.com/WordPress/gutenberg/blob/master/packages/data/README.md#createReduxStore)
that creates a data store definition for the provided Redux store options containing
properties describing reducer, actions, selectors, controls, and resolvers.

Example of the store usage before this change:

    ```notranslate
    registerStore( 'my-store', {
        reducer: ( state = 'OK' ) => state,
        selectors: {
            getValue: ( state ) => state,
        },
    } );
    ```

    ```notranslate
    import { select } from '@wordpress/data';

    const blockTypes = select( 'my-store' ).getBlockTypes();
    ```

Example of the new recommended usage:

    ```notranslate
    import { createReduxStore } from '@wordpress/data';

    export const store = createReduxStore( 'my-store', {
        reducer: ( state = 'OK' ) => state,
        selectors: {
            getValue: ( state ) => state,
        },
    } );

    register( store ); 
    ```

    ```notranslate
    import { select } from '@wordpress/data';
    import { store as myStore } from './store';

    const blockTypes = select( myStore ). getValue();
    ```

This new capabilitycapability A **capability** is permission to perform one or more
types of task. Checking if a user has a capability is performed by the `current_user_can`
function. Each user of a WordPress site might have some permissions but not others,
depending on their role. For example, users who have the Author role usually have
permission to edit their own posts (the “edit_posts” capability), but not permission
to edit other users’ posts (the “edit_others_posts” capability). enables additional
static analysis in the Gutenberg project that improve code quality. We can ensure
now that all stores used in a given module are always properly defined as dependencies.
In effect, it provides the correct loading order of JavaScriptJavaScript JavaScript
or JS is an object-oriented computer programming language commonly used to create
interactive effects within web browsers. WordPress makes extensive use of JS for
a better user experience. While PHP is executed on the server, JS executes within
a user’s browser. [https://www.javascript.com](https://www.javascript.com/) files.
It also opens possibilities for new store implementations that share the same high-
level API.

Finally, there is a new optional ESLint rule [`@wordpress/data-no-store-string-literals`](https://github.com/WordPress/gutenberg/tree/master/packages/eslint-plugin/docs/rules/data-no-store-string-literals.md)
available in `@wordpress/eslint-plugin` package. It ensures that string literals
aren’t used for accessing `@wordpress/data` stores when using API methods. The store
definition is promoted as the preferred way of referencing registered stores.

_This dev notedev note Each important change in WordPress Core is documented in 
a developers note, (usually called dev note). Good dev notes generally include a
description of the change, the decision that led to this change, and a description
of how developers are supposed to work with that change. Dev notes are published
on Make/Core blog during the beta phase of WordPress release cycle. Publishing dev
notes is particularly important when plugin/theme authors and WordPress developers
need to be aware of those changes.In general, all dev notes are compiled into a 
Field Guide at the beginning of the release candidate phase. was written by [@gziolo](https://profiles.wordpress.org/gziolo/)._

[#5-7](https://make.wordpress.org/core/tag/5-7/), [#block-editor](https://make.wordpress.org/core/tag/block-editor/),
[#dev-notes](https://make.wordpress.org/core/tag/dev-notes/)

### Share this:

 * [  Threads ](https://make.wordpress.org/core/2021/02/22/changes-in-wordpress-data-api/?share=threads)
 * [  Mastodon ](https://make.wordpress.org/core/2021/02/22/changes-in-wordpress-data-api/?share=mastodon)
 * [  Bluesky ](https://make.wordpress.org/core/2021/02/22/changes-in-wordpress-data-api/?share=bluesky)
 * [  X ](https://make.wordpress.org/core/2021/02/22/changes-in-wordpress-data-api/?share=x)
 * [  Facebook ](https://make.wordpress.org/core/2021/02/22/changes-in-wordpress-data-api/?share=facebook)
 * [  LinkedIn ](https://make.wordpress.org/core/2021/02/22/changes-in-wordpress-data-api/?share=linkedin)

 1. ![](https://secure.gravatar.com/avatar/d4015f6437cf56ccff9d0beb2085f38f94e240969384f8301a540d3eee6d33d4?
    s=32&d=mm&r=g)
 2.  [helgatheviking](https://profiles.wordpress.org/helgatheviking/)  2:56 pm _on_
    March 12, 2021
 3. Hi all… I’m not sure if it’s related to this, but in my Radio Buttons for Taxonomies
    pluginPlugin A plugin is a piece of software containing a group of functions that
    can be added to a WordPress website. They can extend functionality or add new features
    to your WordPress websites. WordPress plugins are written in the PHP programming
    language and integrate seamlessly with WordPress. These can be free in the WordPress.
    org Plugin Directory [https://wordpress.org/plugins/](https://wordpress.org/plugins/)
    or can be cost-based plugin from a third-party. I was using [`register_rest_field()`](https://github.com/helgatheviking/Radio-Buttons-for-Taxonomies/blob/master/radio-buttons-for-taxonomies.php#L341)
    to add a property to the taxonomyTaxonomy A taxonomy is a way to group things together.
    In WordPress, some common taxonomies are category, link, tag, or post format. [https://codex.wordpress.org/Taxonomies#Default_Taxonomies](https://codex.wordpress.org/Taxonomies#Default_Taxonomies).
    APIAPI An API or Application Programming Interface is a software intermediary that
    allows programs to interact with each other and share data in limited, clearly 
    defined ways. response. And then using that [property in the Javascript](https://github.com/helgatheviking/Radio-Buttons-for-Taxonomies/blob/master/js/src/radio-term-selector.js#L505)
    to add a “No term” radio element that clears the term selected.
 4. As of WP 5.7 that property in the response no longer seems to be coming through
    to the script and I am stumped as to why. Does this ring any bells for anyone?

Comments are closed.

# Post navigation

[← New block variation APIs in 5.7](https://make.wordpress.org/core/2021/02/22/new-block-variation-apis-in-5-7/)

[A Week in Core – February 22, 2021 →](https://make.wordpress.org/core/2021/02/23/a-week-in-core-february-22-2021/)