For my react app, I have built many custom middlewares and passed them in the applyMiddleware()
. Because I have so many, the redux store file is looking a little congested. Is it a good practice to pass them all in the applyMiddleware()
or import them in a separate file within a function and then pass that function in the applyMiddleware()
to keep it clean?
// Redux store
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
export const store = createStore(
reducers,
composeEnhancers(
applyMiddleware(...xMdl, ...yMdl, ...zMdl, ...nAmountsOfMdl),
)
);
I prefer to make groups for reducers using combineReducers. ill share my middleware setup, hope it's helpful for u!
store.config.js :
index.js (in reducers folder) :
Note: I did this on a large project with connected-react-router, maybe it's not good for every project.