The initialState
of your application shoudln't be {}
, it's the value you pass when creating the store.
This is also called the preloadedState
in case you are implementing a sort of local state persistence...
Thus you usually don't want to break anything and set the state to an empty object, instead you should do something like :
// initialState should be exported somewhere in your application
// when the store is created, and imported in the reducer.
switch(action.TYPE){
case types.LOGOUT:
return { ...initialState };
}
It's important that you shouldn't implement any action in more than a reducer combineReducers
calls all reducers with the current state, each reducer will return the state as-is if no change is required, thus the type.LOGOUT action should only be on the relevant reducer, that's user
or settings
depending on the application.