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 applicationdispatch(action)
: Dispatches an action and is the only way to trigger a state changesubscribe(listener)
: Adds a change listener that is called any time an action is dispatchedreplaceReducer(nextReducer)
: Replaces the reducer that is currently used by the store to calculate the state
Getting ready
To work with Redux, we need to install the following packages:
npm install redux react-redux
How to do it...
First, we need to create a file for our store at src/shared/redux/configureStore.js
:
- Let's go ahead and write the following code:
// Dependencies import { createStore } from 'redux'; // Root Reducer import rootReducer from '../reducers'; export default function configureStore(initialState...