How to add multiple middleware to Redux?
applyMiddleware takes each piece of middleware as a new argument (not an array). So just pass in each piece of middleware you'd like.
const createStoreWithMiddleware = applyMiddleware(ReduxThunk, logger)(createStore);
applyMiddleware
should pass into createStore as the second parameter. applyMiddleware
can have multiple middlewares as arguments.
const store = createStore(reducers, applyMiddleware(ReduxThunk, logger));
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.querySelector('#app')
);
answer of andy's is good, but, consider your middlewares growing, below codes will be better:
const middlewares = [ReduxThunk, logger]
applyMiddleware(...middlewares)