You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ A api call lifecycle library for redux combined with redux thunk to be reused for the entire project,
from action to reducer.
action.
import{ApiCall}from'simple-api-call-life-cycle';// Passing the type and define the action.constFETCH_PRODUCTS='FETCH_PRODUCTS';constfetchProductsAction=newApiCall(FETCH_PRODUCTS);constfetchProductsRequest=axios.get('url');exportconstfetchProducts=fetchProductsAction.fetch.bind(fetchProductsAction,fetchProductsRequest);export{fetchProductsAction};
reducer.
import{fetchProductsAction}from'../actions';constINITIAL_STATE={isInProgress: undefined,isCompleted: undefined,hasFailed: undefined,products: []};exportdefault(state=INITIAL_STATE,action)=>{switch(action.type){casefetchProductsAction.init:
// set loading to be true.casefetchProductsAction.success:
// Promise resolvedcasefetchProductsAction.fail:
//default:
returnstate;}};