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

159
Visualizações
Requests repeat several times in React

I have an array

let results = [
   {id: 34},
   {id: 32},
   {id: 35},
]

When I use for each with useEffect, the request sends a lot. It repeats several times, but I only use one place. I wrote results in the dependencies, but it did not work. I need the requests send one time for ID

my function

 useEffect(() => {
    results.forEach(async (data) => {
      const resp = await axios.get(`https://nehra.az/public/api/product/${data.id}`);
      console.log(resp);
    });
  }, []);

My Network

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

useEffect is a side-effect to the rendering. The fact that this is triggered several times means that you had several renderings for the component. You will need to either use some property to know whether the requests were already sent, or move this code into a place that's executed exactly once.

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