Skip to content

Instantly share code, notes, and snippets.

@mattlockyer
Created January 5, 2019 17:52
Show Gist options
  • Save mattlockyer/4a7e3b1fdf649d7735b2207802277e25 to your computer and use it in GitHub Desktop.
Save mattlockyer/4a7e3b1fdf649d7735b2207802277e25 to your computer and use it in GitHub Desktop.
Generic Reducer for Redux - update state with any action key/vaue passed (excluding type)
//generic event type for updating state
export const UPDATE = 'STATE_UPDATE'
//generic reducer for updating state
export const reducer = (state, action) => {
//console.log(action)
const { type } = action
switch (type) {
case UPDATE:
const a = { ...action }
delete a.type
return { ...state, ...a }
default:
return state
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment