Skip to content

Instantly share code, notes, and snippets.

@AshutoshSajan
Created January 24, 2020 16:46
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 AshutoshSajan/1dd7ad0e20885a8911c28e33f80197b4 to your computer and use it in GitHub Desktop.
Save AshutoshSajan/1dd7ad0e20885a8911c28e33f80197b4 to your computer and use it in GitHub Desktop.
const initialState = {
isLoading: true,
user: null
}
export default function usersReducer(state = initialState, action) {
switch (action.type) {
case 'LOGIN':
return {
...state,
isLoading: false,
token: action.payload.token,
user: action.payload.user,
};
case 'REGISTER':
return {
...state,
isLoading: false,
token: action.payload.token,
user: action.payload.user,
};
case 'UPDATE_USER':
return {
...state,
isLoading: false,
user: action.payload.user,
};
case 'LOGOUT':
localStorage.clear();
return {
...state,
isLoading: true,
user: null,
token: null,
};
default:
return state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment