We are now going to set up the redux-thunk middleware:
- As with all libraries, we first need to install redux-thunk with npm:
npm install --save redux-thunk
- Now, we need to import and load the middleware when creating our store. As we will use the same middleware for our development and production store, we create a new src/store/middleware.js file and import redux-thunk there:
import thunkMiddleware from 'redux-thunk'
- We also import the applyMiddleware helper function from Redux:
import { applyMiddleware } from 'redux'
- Then, we can create and export our middleware:
const middleware = applyMiddleware( thunkMiddleware)export default middleware
- Now, all that's left to do is use the middleware while ...