Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const initialStateSchema = {
- user: {},
- };
- let initialState = initialStateSchema
- var stateLocal = localStorage.getItem('state');
- if (stateLocal && stateLocal !== undefined) {
- try {
- initialState = JSON.parse(stateLocal);
- }
- catch (e) {
- initialState = initialStateSchema
- }
- }
- const data = (state = initialState, action) => {
- let stateReturn = state;
- switch (action.type) {
- case 'USER_LOGIN_SUCCESS':
- stateReturn = { ...state, user: Object.assign({}, action.payload) };
- break;
- default:
- break;
- }
- if (stateReturn !== null) {
- localStorage.setItem('state', JSON.stringify(stateReturn));
- return stateReturn;
- }
- }
- export default data;
Add Comment
Please, Sign In to add comment