Skip to content

Instantly share code, notes, and snippets.

@jdmorlan
Created August 21, 2016 22:36
Show Gist options
  • Save jdmorlan/25f72991146805311449a21e4e5acd09 to your computer and use it in GitHub Desktop.
Save jdmorlan/25f72991146805311449a21e4e5acd09 to your computer and use it in GitHub Desktop.
Remove the switch statement from Redux reducers!
const updateLocation = (state, action) => {
return Object.assign({}, state, ...)
}
const actionHandlers = {
'UPDATE_LOCATION': updateLocation
}
const reducer = (state = initialState, action) => {
const handler = actionHandlers[action.type]
if (!handler) return state
return handler(state, action)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment