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

123
Vistas
ReactJS not re-rendering component when setting global state in a loop

for (const method of methodsToRun) {
    let result = /*runStuff*/;
    results.push(...(JSON.parse(result)));
    setGlobalState('dataOutput', results);
}

I have this loop that runs an algorithm on every iteration (each iteration may take a few seconds to complete). I need the component depending on the 'dataOuput' global state to re-render when updated on every iteration, but it updates only when the loop is done. I guess this is due to the fact that JS is single-threaded and the re-rendering gets queued, any workarounds to ensure re-rendering in every iteration of the loop?

PS: I'm using react-hooks-global-state to manage the global state, not Redux

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Maybe you should use setTimeout. All setState events in 1ms in react occur same time

about 4 years ago · Santiago Gelvez 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