Advertisement
Qpel

reduceris

Mar 2nd, 2020
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {
  2.     SUCCESS_USERS_RESULT,
  3.     FAILURE_RESULT,
  4.     REQUEST_USERS
  5. } from "../constants"
  6.  
  7. const initialState = {
  8.     users: [],
  9.     isFetching: false,
  10.     isLoaded: false,
  11.     activeUserId: 0,
  12.     checkedCityId: 0
  13. }
  14.  
  15. function userReducer(state = initialState, action) {
  16.     switch(action.type) {
  17.         case SUCCESS_USERS_RESULT:
  18.             return {
  19.                 ...state,
  20.                 isFetching: false,
  21.                 users: action.users,
  22.                 isLoaded: true,
  23.                 activeUserId: action.activeUserId
  24.             };
  25.         case REQUEST_USERS:
  26.             return {
  27.                 ...state,
  28.                 isFetching: true,
  29.                 checkedCityId: action.checkedCityId
  30.             };
  31.         case FAILURE_RESULT:
  32.             return {
  33.                 isFetching: false,
  34.                 error: action.error
  35.             };
  36.         default:
  37.             return state
  38.     }
  39. }
  40.  
  41. export default userReducer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement