Adds support for nesting in any compatible combineReducers function.
No dependencies and no assumptions on which Redux like library you are using.
Tipically you divide your state tree in multiple slices, each handled by its own reducer.
But if you want to further split your slices in even more slices you would have to do:
const postsReducer =;const commentsReducer = ...;const dataReducer =;const rootReducer =;
As you can see you have to call manually combineReducers multiple times, potentially losing the overview of your state shape.
In fact from the example above it is not immediately obvious what the state shape looks like.
This library tries to simplify this workflow by allowing you to specify a reducers map with nested reducing functions.
The example above with nestedCombineReducers would become:
const rootReducer =;
With nestedCombineReducers it should be a bit more clear what the state shape looks like when your are creating the root reducer or any slice reducer.
Keep in mind that you could use nestedCombineReducers to create a slice reducer that will be combined in a root reducer with the usual combineReducers.
nestedCombineReducers is not meant to be used only to create the root reducer.
Minimum ECMAScript version required is ECMAScript 2015 (ES6).
Provides typings for Typescript and it is also written in Typescript.
How do I use it ?
Import nestedCombineReducers from 'nested-combine-reducers'.
Import a combineReducers function from some library.
Call nestedCombineReducers passing in your reducers map and your combineReducers function.
Code example using ECMAScript 2015 (ES6) modules:
;;const someNestedReducersMap =ui:spinner: spinnerReducerdata:posts:items: postItemsReducerfavourites: favouritePostsReducercomments:...const rootReducer = ;
Code example using CommonJS:
const combineReducers = ;const nestedCombineReducers = ;const someNestedReducersMap =ui:spinner: spinnerReducerdata:posts:items: postItemsReducerfavourites: favouritePostsReducercomments:...const rootReducer = ;
Supported combineReducers functions
For every 'officially supported' library there will be a test called Creates a root Reducer from a nested map using combineReducers from X where X is a particular library.
Currently the combineReducers functions from the following libraries are supported or will be supported:
The first obvious limitation is that for very deeply nested objects the recursive approach of nestedCombineReducers will ultimately fails with a stack overflow error, although the chances that you might encounter or create such complicated state shape are very low.
Another limitation is that circular references in the reducers map will also lead to a stack overflow error, but having circular references in your state tree is no supported by any Redux like library that I know of.