getInitialState prevents composing reducers
Closed this issue · 0 comments
rstacruz commented
For bigger apps, it's usually a good practice to create multiple reducers and combine them. Here's an example using compose
(or reduce-reducers):
function shops (state, action) {
...
}
function users (state, action) {
...
}
createStore(compose([ shops, users ])
In these cases, having an initialState
is redundant because there's no need to make initial state on each sub-reducer.
You could've instead done:
function addDefault (state, action) {
if (typeof state === 'undefined') return {} /* initial state */
return state
}
createStore(compose([ addDefault, shops, users ])
The fix is rather easy... just make getInitialState
optional.