Thought on the Reducer
Wondering what you think about doing this for your reducer instead of the switch statement? My thoughts were switch statements could get long, plus maintaining a large one could be annoying. Plus the type key/value pair seems redundant if you make the added state object agnostic of static state names.
const reducer = (state, action) => {
const actionKey = Object.getOwnPropertyNames(action)
return action ? { ...state, [actionKey] : action[actionKey] } : state
}
instead of dispatching like so,
() => dispatch({ type: 'type', thing: false})
you would dispatch like so,
() => dispatch({thing: false})
Reducer and action can be written in any way in your app. Of course your solution can work too. Also depends on the use case. If the action passes simple value, your solution is enough. But usually you need to do more complex operations with your state (merge deeper objects, etc.)