I am getting null in my payload because of late redux form store update

I am conditionally changing one of my values in redux store and calling an API right after that. But that value is still null by the time API response is pending. How can I call API having that value in my payload?

(I am using redux form)

  useEffect(() => {
    
        if(amount <= SMALL_AMOUNT){
            props.changeFormValue('term', 50);
        }
      
    }, [props, amount]);

  ///////////////////////////////////////////////////////////////

    const getSecuredLoanValues = async({
        termValue= _get(formValues, 'term', null),
        ....
        ....
      }) => {

        const payload= {
            term_in_months: termValue,
             ....
             ....
        };
     ....
     ....
    }

 ///////////////////////////////////////////////////////////////

   <Field
       name="term"
       component={Terms}
       label="TERM"
   />

///////////////////////////////////////////////////////////////

const mapDispatchToProps = (dispatch) => ({
    changeFormValue: (field, value) => {
        dispatch(change(FORMS_NAME.LOAN_FORM, field, value))
    },
    changeGlobalFormValue: (field, value) => {
        dispatch(change(FORMS_NAME.ACCESS_SEEKER_GLOBAL, field, value))
    },
});

So when I console log term, I can see it being null initially and then becoming 50. By that time API call has been made and my payload is missing term



Read more here: https://stackoverflow.com/questions/67931882/i-am-getting-null-in-my-payload-because-of-late-redux-form-store-update

Content Attribution

This content was originally published by Sonny49 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: