How to dynamically load reducers for code splitting in a Redux application?

I’m going migrate to Redux.

My application consists of a lot of parts (pages, components) so I want to create many reducers. Redux examples show that I should use combineReducers() to generate one reducer.

Also as I understand Redux application should have one store and it is created once the application starts. When the store is being created I should pass my combined reducer. This makes sense if the application is not too big.

But what if I build more than one JavaScript bundle? For example, each page of application has own bundle. I think in this case the one combined reducer is not good. I looked through the sources of Redux and I have found replaceReducer() function. It seems to be what I want.

I could create combined reducer for each part my application and use replaceReducer() when I move between parts of application.

Is this a good approach?

6 Answers
6

Leave a Comment