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

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

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 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