Created
January 16, 2019 20:00
-
-
Save OleksivO/e169ebe9ff2586ac7a3fc47337912b79 to your computer and use it in GitHub Desktop.
the description for this gist
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
const INITIAL_STATE = { | |
token: null, | |
userId: null, | |
error: null, | |
loading: false, | |
}; | |
// ... | |
const reducer = (state = INITIAL_STATE, action) => { | |
switch(action.type) { | |
case actionTypes.AUTH_START: | |
return {...state, ...{ loading: true, error: null }}; | |
case actionTypes.AUTH_SUCCESS: | |
return {...state, token: action.token, userId: action.userId, loading: false }; | |
case actionTypes.AUTH_FAIL: | |
return {...state, loading: false, error: action.error }; | |
case actionTypes.AUTH_LOGOUT: | |
return {...state, token: null, userId: null }; | |
default: return state; | |
} | |
}; | |
export default reducer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment