Guest User

Untitled

a guest
Jun 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. const initialStateSchema = {
  2. user: {},
  3. };
  4.  
  5. let initialState = initialStateSchema
  6.  
  7. var stateLocal = localStorage.getItem('state');
  8. if (stateLocal && stateLocal !== undefined) {
  9. try {
  10. initialState = JSON.parse(stateLocal);
  11. }
  12. catch (e) {
  13. initialState = initialStateSchema
  14. }
  15. }
  16.  
  17. const data = (state = initialState, action) => {
  18.  
  19. let stateReturn = state;
  20. switch (action.type) {
  21. case 'USER_LOGIN_SUCCESS':
  22. stateReturn = { ...state, user: Object.assign({}, action.payload) };
  23. break;
  24. default:
  25. break;
  26. }
  27.  
  28. if (stateReturn !== null) {
  29. localStorage.setItem('state', JSON.stringify(stateReturn));
  30. return stateReturn;
  31. }
  32. }
  33.  
  34. export default data;
Add Comment
Please, Sign In to add comment