Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

109
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda