Is it a bad idea to use conditions in reducers? Something like this:
case types.SET_SOME_ACTION:
if(typeof someElement !== "undefined") {
return Object.assign({}, state, {
someElement: action.value
})
}
Trying to see if this is an anti-pattern. Thanks.
I believe it is a general consensus to put your business logic in an action creator. That leaves reducers with only one responsibility: to update the state.
See this discussion for more: https://github.com/reactjs/redux/issues/1165
The redux FAQ also recommends a dumb reducer: http://redux.js.org/docs/faq/CodeStructure.html#how-should-i-split-my-logic-between-reducers-and-action-creators-where-should-my-business-logic-go
Personally, I only do simple validation in the redux store, the actual business logic is handled by Redux Observable or Redux Thunk.