Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@OleksivO
Created January 16, 2019 20:00
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 OleksivO/e169ebe9ff2586ac7a3fc47337912b79 to your computer and use it in GitHub Desktop.
Save OleksivO/e169ebe9ff2586ac7a3fc47337912b79 to your computer and use it in GitHub Desktop.
the description for this gist
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