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
Maybe you should use setTimeout. All setState events in 1ms in react occur same time