Skip to content

Instantly share code, notes, and snippets.

@tcelestino
Last active April 26, 2020 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcelestino/1a5fa69f74e29ab6b4952486daa0d972 to your computer and use it in GitHub Desktop.
Save tcelestino/1a5fa69f74e29ab6b4952486daa0d972 to your computer and use it in GitHub Desktop.
reducer without switch statement - based on https://www.valentinog.com/blog/switch/
function reducers(state = initState, action) {
const mapping = {
[ACTION_ONE]: { ...state, token: action.payload },
[ACTION_TWO]: { ...state, error: action.payload }
};
return mapping[action.type] || state;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment