I don't do a lot of React programming anymore, so I hope this one has a simple answer.
I have a mock generator function that returns 3 primes at 2-second intervals. I insert each prime yielded into a list as they are returned. The list does not render until all 3 primes are returned. I'm attaching just the relevant code.
function* testPrimes(addPrime) {
const primes = [3, 5, 7];
let time = Date.now();
let i = 0;
do {
const nTime = Date.now();
if (nTime - time > 2000) {
yield primes[i++];
time = nTime;
}
} while (i < primes.length);
}
In the parent component, I populate the contained list (which is just divs, actually):
return (
<div>
<div>{appState === RUNNING ? "Running..." : "Stopped"}</div>
<div className="row">
{(() => {
if (appState === RUNNING) {
for (const prime of testPrimes()) {
console.log("foo");
primes.push(<Response {...{ prime, key: prime }} />);
}
}
})()}
{primes}
</div>
</div>
);
I see the "foo"s printed out at intervals, but the <Response> components are rendered all at once.