Advertisement
Hen_B_S

AuthInitalState and CombineReducers

Feb 3rd, 2023
998
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TypeScript 0.72 KB | Source Code | 0 0
  1. import { AUTH_FAILURE, AUTH_REQ, AUTH_SUCCESS } from "types/authTypes";
  2. import { combineReducers } from "redux";
  3. import auth from './auth';
  4.  
  5. const initialState = {
  6.   users: {},
  7.   error: "",
  8.   loading: false,
  9. };
  10.  
  11. export const auth = (state = initialState, action: any) => {
  12.   switch (action.type) {
  13.     case AUTH_REQ:
  14.       return { ...state, error: "", loading: true };
  15.  
  16.     case AUTH_SUCCESS:
  17. const data = action.payload;
  18.     return { ...state, error:'', loading:false, user: data };
  19.  
  20.     case AUTH_FAILURE:
  21.       const error = action.payload;
  22.       return { ...state, loading: false, error: error };
  23.  
  24.     default:
  25.       return state;
  26.   }
  27. };
  28.  
  29. //Combine Reducers
  30.  
  31. export default combineReducers({
  32.     auth
  33. })
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement