• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

90
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!");
      }
almost 3 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.

almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error