Advertisement
chukwuyem

Untitled

Oct 16th, 2020
1,841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {AUTH_USER_REQUEST, AUTH_USER_SUCCESS, AUTH_USER_FAILURE} from './authTypes'
  2.  
  3. const initialState = {
  4.     loading: false,
  5.     users: {
  6.        
  7.     },
  8.     error: '',
  9.     token: null
  10. }
  11.  
  12. const authReducer = (state = initialState, action) => {
  13.     switch(action.type) {
  14.         case AUTH_USER_REQUEST:
  15.             return {
  16.                 ...state,
  17.                 loading: true,
  18.                 token: null
  19.  
  20.             }
  21.  
  22.        
  23.             case AUTH_USER_SUCCESS:
  24.             return {
  25.                 loading: false,
  26.                 users: action.payload,
  27.                 error: '',
  28.                 token: 1
  29.  
  30.                
  31.             }
  32.    
  33.             case AUTH_USER_FAILURE: return {
  34.                 loading: false,
  35.                 users: {},
  36.                 error: action.payload,
  37.                 token: null
  38.  
  39.                
  40.             }
  41.    
  42.             default: return state
  43.     }
  44. }
  45.  
  46. export default authReducer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement