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

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

0

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

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