Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda