Created
January 5, 2019 17:52
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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