concept applymiddleware in category react

This is an excerpt from Manning's book Redux in Action.
Add the middleware via the applyMiddleware function exported by Redux, as shown in the following listing.
We’ve covered most of the usual suspects you’d find in a React/Redux application: actions, reducers, and the store. To update a state in your application using Redux, you need all three. You have one more core actor that’s key to this whole operation: middleware. If you’ve spent any time in chapter 4, you’ve already come face-to-face with middleware and lived to tell the tale. When you added redux-thunk to the Parsnip project, you learned how to apply middleware to Redux using the applyMiddleware function, but not necessarily how to create your own. In this chapter, we’ll look more in depth at how middleware works, how to create it, and what use cases it can be a good fit for.
Open index.js, import the logger, and add it to the argument list for applyMiddleware alongside thunk, as shown in listing 5.2. Whenever you want to add a new middleware to your applications, you’ll follow this process. Note that you add the logger middleware last, and they run in the order that you pass them to applyMiddleware. It’s not critical in this case, that the middleware be in any particular order, but you should be aware of the significance of their order.
Listing 6.6. src/index.js
import createSagaMiddleware from 'redux-saga'; #1 import rootSaga from './sagas'; #2 const sagaMiddleware = createSagaMiddleware(); #3 const store = createStore( reducer, composeWithDevTools(applyMiddleware(thunk, sagaMiddleware)) #4 ); sagaMiddleware.run(rootSaga); #5 #1 createSagaMiddleware is the default export of redux-saga. #2 redux-saga needs to know which saga (or sagas) to run. #3 createSagaMiddleware is a factory function, used to create sagaMiddleware. #4 Adds the saga middleware to the list in applyMiddleware #5 Finally, initiate the saga with the run method on the sagaMiddleware instance. !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":66},{\"line\":0,\"ch\":68}],[{\"line\":12,\"ch\":0},{\"line\":12,\"ch\":2}],[{\"line\":1,\"ch\":66},{\"line\":1,\"ch\":68}],[{\"line\":13,\"ch\":0},{\"line\":13,\"ch\":2}],[{\"line\":3,\"ch\":66},{\"line\":3,\"ch\":68}],[{\"line\":14,\"ch\":0},{\"line\":14,\"ch\":2}],[{\"line\":7,\"ch\":66},{\"line\":7,\"ch\":68}],[{\"line\":15,\"ch\":0},{\"line\":15,\"ch\":2}],[{\"line\":10,\"ch\":66},{\"line\":10,\"ch\":68}],[{\"line\":16,\"ch\":0},{\"line\":16,\"ch\":2}]]"} !@%STYLE%@!