JSPM

@wordpress/core-data

2.0.13
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 93915
  • Score
    100M100P100Q149994F
  • License GPL-2.0-or-later

Access to and manipulation of core WordPress entities.

Package Exports

  • @wordpress/core-data

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@wordpress/core-data) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Core Data

Core Data is a data module intended to simplify access to and manipulation of core WordPress entities. It registers its own store and provides a number of selectors which resolve data from the WordPress REST API automatically, along with dispatching action creators to manipulate data.

Used in combination with features of the data module such as subscribe or higher-order components, it enables a developer to easily add data into the logic and display of their plugin.

Installation

Install the module

npm install @wordpress/core-data --save

This package assumes that your code will run in an ES2015+ environment. If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using core-js or @babel/polyfill will add support for these methods. Learn more about it in Babel docs.

Example

Below is an example of a component which simply renders a list of authors:

const { withSelect } = wp.data;

function MyAuthorsListBase( { authors } ) {
    return (
        <ul>
            { authors.map( ( author ) => (
                <li key={ author.id }>{ author.name }</li>
            ) ) }
        </ul>
    );
}

const MyAuthorsList = withSelect( ( select ) => ( {
    authors: select( 'core' ).getAuthors(),
} ) )( MyAuthorsListBase );

Actions

The following set of dispatching action creators are available on the object returned by wp.data.dispatch( 'core' ):

Refer to actions.js for the full set of dispatching action creators. In the future, this documentation will be automatically generated to detail all available dispatching action creators.

Selectors

The following selectors are available on the object returned by wp.data.select( 'core' ):

Refer to selectors.js for the full set of selectors. In the future, this documentation will be automatically generated to detail all available selectors.



Code is Poetry.