Skip to main content
The WordPress data module serves as a centralized hub to manage application state for both plugins and WordPress itself. It provides tools to manage data within and between distinct modules, designed as a modular pattern that scales from simple plugins to complex single-page applications.

Architecture

The data module is built upon and shares many core principles with Redux, but includes several distinguishing characteristics specific to WordPress:
  • Modular stores: Separate but interdependent stores with standardized patterns
  • Selector-based access: Selectors as the primary entry point for data access
  • Built-in async handling: Resolvers and thunks for side effects
  • Entity-based system: Standardized approach to working with WordPress data
The data module follows Redux principles but is NOT just “Redux for WordPress”. It includes custom features like resolvers, entity management, and automatic cache invalidation.

Core Concepts

Stores

Stores are created using createReduxStore and registered with register. Each store contains:

Selectors

Selectors retrieve and derive values from state. They accept state as the first argument, followed by any additional parameters:
Access selectors using the select function:

Actions

Actions are functions that return action objects to dispatch to the reducer. They describe state changes:
Dispatch actions using the dispatch function:
Action creators returned by dispatch return promises when called, allowing you to await their completion.

Resolvers

Resolvers are side effects for selectors. They fulfill data requirements the first time a selector is called:
When you call select( store ).getPrice( 'hammer' ) for the first time:
  1. The selector returns null (no data yet)
  2. The resolver triggers, fetching data from the API
  3. The resolver dispatches actions to store the data
  4. The selector now returns the fetched data on subsequent calls

Key Differences from Redux

Subscriptions

In @wordpress/data, subscribers are only called when state has actually changed, unlike Redux where subscribers are called on every dispatch.

Modular Pattern

Stores are registered with unique names and accessed through a central registry, enabling:
  • Cross-store selectors using createRegistrySelector
  • Store-specific subscriptions
  • Dynamic store registration

Split HOCs

withSelect and withDispatch are separate (unlike React Redux’s combined connect), reflecting that dispatch doesn’t depend on state subscriptions.

Core Data Entities

The @wordpress/core-data package provides a standardized interface for WordPress entities (posts, pages, users, etc.):
Entity records automatically:
  • Cache API responses
  • Handle resolution status
  • Track edits separately from persisted data
  • Support undo/redo operations

React Integration

useSelect Hook

Retrieve data in React components:

useDispatch Hook

Dispatch actions from React components:

Performance Optimization

Batching Updates

Use registry.batch() to group multiple updates and trigger listeners only once:

Memoized Selectors

Use createSelector for expensive computations:

Next Steps