Created
March 16, 2020 19:05
-
-
Save jonwaldstein/b4eccfe774c48db5d0a0a0f4f1be9bca to your computer and use it in GitHub Desktop.
React context state reducer
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
const UPDATE_STATE = 'update_state'; | |
export default function reducer(state, action) { | |
switch (action.type) { | |
case UPDATE_STATE: | |
return { | |
...state, | |
...action.newData, | |
}; | |
default: | |
return state; | |
} | |
} | |
/** | |
* Set data action | |
* @param {object} newData | |
* @returns {{type: string, newData: Object}} | |
*/ | |
export function setData(newData) { | |
return { | |
type: UPDATE_STATE, | |
newData, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment