Skip to content
Advertisement

How to create multiple reducers with multiple modules?

I still don’t have much experience with Redux.

But I have a situation at work where we will have an application with several modules.

Each module will have its own store.

I’m not able to merge all these stores into one store and then create a general store for all the project.

Could you tell me how can i do this?

enter image description here

enter image description here

JavaScript

I created a test project in codesandbox.io just to demonstrate the idea of what the project will be like.

Advertisement

Answer

combineReducers(reducers) helper function turns an object whose values are different reducing functions into a single reducing function. It can’t combine multiple stores.

Besides, the best practice is Only One Redux Store Per App

A standard Redux application should only have a single Redux store instance, which will be used by the whole application

You can have each module act as a first-level slice on the redux state tree like this:

store.js:

JavaScript

The structure of the redux state tree will be like this:

JavaScript

If the module becomes large in the future, you can split it into a separate application with its own redux store.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement