Last active
April 26, 2020 21:06
-
-
Save tcelestino/1a5fa69f74e29ab6b4952486daa0d972 to your computer and use it in GitHub Desktop.
reducer without switch statement - based on https://www.valentinog.com/blog/switch/
This file contains 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
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