Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork15.2k
Description
I might be missing something, but I don't understand why a reducer should have a default state. Most of the doc have something like:
functionreducer(state=initialState,action){...}
I don't see why the reducer should know anything about the default state. The state is managed by the store, the reducer is a pure function that does its job with whatever you give it as argument and not trying to guess what the state is if there is none. But well, I though that it was ok as long as I wasn't forced to put a default state inside the reducer.
Except thatcombineReducers forces me to put a default state. According tothis code, anundefined state will be triggered by Redux to the reducer. Why? My store will pass the default state, so it will never beundefined in practice. My reducer is simple: if it knows the action, it will do something, if not, it will return the state. If the state isundefined, it will returnundefined.
Even worse, what if I want to use the same reducer in several different stores with different initial states? Agreed I can always put a fake default state inside the reducer (like0) and it will be overridden by the store default states, whatever they are, but it feels just wrong.