1. Getting Started
2. Basic Concepts
3. Handlers
4. Advanced Concepts
4.0.1 Creating Custom Reducer4.0.2 Modifying api end points reducer constants# Modifying api end points reducer constants4.0.3 Don't reset on setting to initial state4.0.4 Cancelling Api Calls4.0.5 Axios Interceptors4.0.6 Inject saga and reducer to the store4.0.7 Inject saga and reducer to the store by using hooks4.0.8 Util Functions4.0.9 PARAMS4.1.0 Handling Multiple tasks
# Modifying api end points reducer constants
import {HOC,commonConstants,store,newObject,} from "react-boilerplate-redux-saga-hoc";const { CALL, ON_SUCCESS } = commonConstants;const reducer = ({constants,successData,restSuccessData,payload,query,state,params,restPayload,loadingStatus,statusCode,type,reset,newState,method,statusMessage,errorData,restErrorData,resetState,initialState,commonHandler,commmonErrorHandler,defaultReducerHandler,}) => {switch (type) {case "RESET":switch (method) {case ON_SUCCESS:return newObject(state, resetState);default:return state;}case constants.VERIFY_OTP_API[CALL]:switch (method) {case ON_SUCCESS:return newState(({ [type]: Data }) => ({profile: successData,isLoggedIn: !!successData.data.mobile_number,[type]: newObject(Data, {lastUpdated: generateTimeStamp(),data: successData,}),}));default:return defaultReducerHandler(); // for handling others such as Error}case authenticationConstants.USER_PROFILE_API[CALL]:switch (method) {case ON_SUCCESS:return newState(({ profile, [type]: Data }) => ({authorization: true,isLoggedIn: !!successData.name,profile: newObject(profile, successData),[type]: newObject(Data, commonHandler()), // you can use commonHandler for handling task by itsself}));case ON_ERROR:return newObject(state, ({ [type]: Data }) => ({isError: true,isLoggedIn: false,[type]: newObject(Data, commmonErrorHandler()), // you can use commmonErrorHandler for handling error by itsself}));case ON_UNMOUNT: {return reset(); // This is just an example don't do this if it is not required.Reset will be handled by itsself}default:return state;}default:return defaultReducerHandler();}};const AuthenticationHOC = HOC({initialState: {profile: {},},apiEndPoints: {TEST_API: {},VERIFY_OTP_API: {url: `users/verify-otp/`,method: "POST",},REGISTER_API: {url: `users/user-signup/`,method: "POST",},dontReset: {REGISTER_API,},},reducer,constantReducer: ({type,state,action,constants,initialState,resetState,}) => {if (type === "LOGOUT")return action.payload.resetEntireState ? initialState : resetState; // resetState wont reset if you specify the api in (dontReset) key while creating hocreturn state;},name: "Auth",});