AllenYuan

auth - update authreducer

Apr 24th, 2020
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export default (state = {}, action) => {
  2.   switch (action.type) {
  3.     // LOGIN => got login response => turn off loading state, put errors in state
  4.     case 'LOGIN':
  5.       return {
  6.         ...state,
  7.         inProgress: false,
  8.         errors: action.error ? action.payload.errors : null
  9.       };
  10.     // ASYNC_START => made http request => set loading state
  11.     case 'ASYNC_START':
  12.       if (action.subtype === 'LOGIN' || action.subtype === 'REGISTER') {
  13.         return { ...state, inProgress: true };
  14.       }
  15.       break;
  16.     // UPDATE_FIELD_AUTH => new value in form field => update value in state
  17.     case 'UPDATE_FIELD_AUTH':
  18.       return { ...state, [action.key]: action.value };
  19.     default:
  20.       return state;
  21.   }
  22. };
Advertisement
Add Comment
Please, Sign In to add comment