Configuring your Application to use Redux
Once you have the reducers and actions created, it is time to configure your application to make use of Redux. For this, we will need to:
Create our application reducer
Create and configure a store
Subscribe to the store and update the view
Create Our Application Reducer
What combineReducers
does, is allows us to break out our application into smaller reducers with a single area of concern. Each reducer that you pass into it, will become a property on the state. So when we are subscribing to our state changes, we will be passed in a state object with a property counter, and any other reducers you have provided.
Create and Configure a Store
When creating a store in redux, this is where you provide the middleware you want to use, and the reducer that you want to have for your application.
In this example, we are creating a store that is using the thunk
middleware, which will allow our actions to return non-JSON objects such as promises. We could also use other middlewares such as redux-logger
, which will provides some logging functionality to the application.
Subscribe to State Changes
Now that we have created our state reducer, and created a store. We now need to subscribe to the store and update our view with the latest state.
Full Example
Last updated
Was this helpful?