Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
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 answers
Answer question

0

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

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!