chainReducers
Creates a reducer that chains together a sequence of (sub-)reducers.
Details
Given a sequence of (sub-)reducers, chainReducers
creates a reducer which forwards incoming actions to each of these "child" reducers. More specifically, the reducer:
calls the first child reducer with the received state
passes the resulting state (and the same action) to the next reducer
repeats step 2 until reaching the last reducer, whose returned state is finally returned by the
chainReducers
reducer.
Note that the first child reducer in the chain is the only one which needs to handle an undefined
state by returning the initial state; all others can be sub-reducers - such as the ones returned by onAction
- which assume that they are only ever called with a defined, already-initialized state.
Examples
Chaining withInitialState
and onAction
reducers:
See Also
Reducers guide
Last updated