Is it best to control defaults for state from reducers or selectors
Issue with reducer option I see is the established convention is to just return state and would be breaking that convention.
If use selectors they would all have logic
if (state.something === null)
return someDefaultValue
else
return state.someValue
However, default values are also set in the declaration of reducer. e.g.,
const someReducer = (state = {}, {type, payload})
Using auth-selectors/getLoggedIn as an example
the default state for auth is {} so the loggedIn key doesn't exist
rather than the auth reducer just returning state as the default, should it set values as needed? E.g.,
...
default:
...state
loggedIn: false
this seems advantageous in that the logic for the default is with the logic for all other cases instead of having the default value in a separate place, i.e., selectors.
using the default case as a place to set defaults breaks the app because every time the reducers are called for a case not covered in a given reducer, the default values will be set and overwrite perviously set non-default values.
therefore, default values should be set in the selector
Is it best to control defaults for state from reducers or selectors Issue with reducer option I see is the established convention is to just return state and would be breaking that convention. If use selectors they would all have logic
However, default values are also set in the declaration of reducer. e.g.,
Using auth-selectors/getLoggedIn as an example
therefore, default values should be set in the selector