detailsReducer.js 515 Bytes
import { FETCH_DETAILS_FAIL, FETCH_DETAILS_SUCCESS, CLEAR_ERRORS } from "../constants/detailsConstants";

export const detailReducer = (state = { details: [] }, action) => {
  switch (action.type) {
    case FETCH_DETAILS_SUCCESS:
      return {
        details: action.payload.data
      };
    case FETCH_DETAILS_FAIL:
      return {
        error: action.payload.error.message
      };
    case CLEAR_ERRORS:
      return {
        ...state,
        error: null
      };

    default:
      return state;
  }
};