Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
How to pervent to send http request until the perious one is fulfilled?

I have a case that: when the user changes the input, with each change, I have to send an HTTP request to get some data from the server. when I get the data I update my state with new data and that, of course, affects the view. so, the problem is when the user changes the input very fast the requests don't fulfill respectively and this leads to an improper view at the end. so, I want to not send the request until the previous one is fulfilled.

const parallel = (...Promises) => {
  return Promise.all(Promises);
};

export function parentAccHandler(e, inputFiled) {
  const parentAccValue = e.target.value;
  const { fields } = this.state;
  parallel(
    getUsedRecord(fields),
    axios.get(`chartofaccounts/nextPK/${parentAccValue}`)
  )
    .then(([usedRecord, nextPkRes]) => {
      this.setState((state, props) => {
        const { fields } = state;
        fields.acc_no.value = nextPkRes.data.next_PK
          ? nextPkRes.data.next_PK
          : "";
        return {
          fields: updateOnParentAcc.call(this, fields, usedRecord, "PRESENT"),
        };
      });
    })
    .catch((err) => {
      this.setState((state, props) => {
        let { fields } = state;
        fields.acc_no.value = "";
        fields.parent_acc.prevReqStatus = "FULFILLED";
        if (parseInt(parentAccValue) === 0) {
          fields = updateOnParentAcc.call(this, fields, null, "ZERO");
        } else {
          fields = updateOnParentAcc.call(this, fields);
        }
        return {
          fields: fields,
        };
      });
    });
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Well if you wrap the input fields and other stuff into a <fieldset> and give it the disabled="disabled" attribute it will disable all fields.

When you do Axios request, add disabled="disabled" attribute to fieldset, and when request success remove that attribute.

Make it as state then just setState to that.

Other method would be to show/hide overlay/loading to prevent clicking other fields.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!