The store – combining actions and reducers
By now, we might be wondering what exactly Redux is (besides a set of principles and some helper functions). Essentially, Redux brings actions and reducers together. It provides a store, which contains the application state and provides some functions to do the following:
- Access the application state:Â
store.getState()
- Dispatch actions:Â
store.dispatch(action)
- Register listeners:Â
store.subscribe(listener)
According to the official documentation of Redux,Â
Redux is a predictable state container for JavaScript apps
.
The state container (store) is the heart of Redux: It contains your application state and does not allow external changes. Redux only allows changes through actions, which get passed to pure reducer functions. These restrictions that Redux enforces are what makes your application state predictable.
Creating the store
We will now cover how to use Redux to create a store from our appReducer
, how to listen to changes in the store, and how to dispatch...