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

110
Views
calling setState function multiple Time

I'm calling setState function so many time in a row (by pressing down button). but problem is react js stop updating state after some updating(40-50 times). I'm increasing sold value by one on each click.

I want to know is it the normal behaviour of react js? or I'm missing something?

axios.put(`http://localhost:5000/soldUpdate`,item)
   .then(res => {
      const {quantity,sold,...rest} = item;
      const newQuantity = parseInt(quantity)-1;
      const newSold = parseInt(sold)+1;
      if(res.status===200){
         setItem({...rest,quantity:newQuantity,sold:newSold})
      } else {
         console.log("not updated!");
      }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

After too many clicks in a row, the API you're calling may block your request. In that case, you won't get any response, but an error so .then() isn't going to be called. That's probably the reason why your state isn't changing. The best way to check if the API responds with an error is by .catch().

Also, check the official Axios docs on handling errors.

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!