Creating a Redux Store

A store holds the whole state of your application, and the only way to change the state inside is by dispatching an action. A store is not a class; it is just an object with a few methods on it.

The store methods are as follows:

  • getState()Returns the current state of your application
  • dispatch(action): Dispatches an action and is the only way to trigger a state change
  • subscribe(listener): Adds a change listener that is called any time an action is dispatched
  • replaceReducer(nextReducer): Replaces the reducer that is currently used by the store to calculate the state

Get React Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.