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
My app has over 75 different types of axios actions using this library and I would like to handle the loading state in a generalized way rather than hundreds of lines of case TYPE.FOO_SUCCESS in my reducers.
For context: I have a single page application with loading spinners at the "page" level and on individual sub components. They all use the same "state.loading" state.
Is there a best practice or pattern here?
I'v tried this:
letloading=falseletrequestsHappening=0;exportconstrootReducer=(state=initialState,action)=>{if(isAxiosRequest(action)&&!/(.*)_(SUCCESS|FAIL)/.exec(action.type)){requestsHappening+=1loading=true}elseif(isAxiosRequest(action)){requestsHappening-=1loading=requestsHappening!==0;}switch(action.type){// hundreds of lines of Redux boilerplatedefault:
return{
...state,
loading,}}}
But I can't seem to make it work.
The text was updated successfully, but these errors were encountered:
I would guess that you can add interceptors like they show in the documentation and on request success use the dispatch you get from the config to dispatch something like dispatch({ type: 'REQUEST_START' })
and in your interceptors for response dispatch({ type: 'REQUEST_RESOLVED' })
Hello,
My app has over 75 different types of axios actions using this library and I would like to handle the loading state in a generalized way rather than hundreds of lines of
case TYPE.FOO_SUCCESS
in my reducers.For context: I have a single page application with loading spinners at the "page" level and on individual sub components. They all use the same "state.loading" state.
Is there a best practice or pattern here?
I'v tried this:
But I can't seem to make it work.
The text was updated successfully, but these errors were encountered: