Episode 08 game · Raiden · Lightning
Thaw the Frozen Echo
Kai’s timer says 1 forever while the console keeps saying 0. Run it and hear the echo, give the interval code that asks for the latest value, then prove it with six ticks.
count1 · Hear the echo
This is Kai’s real code running in a tiny React stand-in. Start the timer and watch the screen, the console and the renders for at least five ticks.
useEffect(() => {
const id = setInterval(() => {
console.log(count);
setCount(count + 1);
}, 1000);
return () => clearInterval(id);
}, []);
2 · Ask for the latest
The interval was born in render 1, so every count it reads is render 1’s 0. Fix both lines inside it.
3 · The six-tick test
A fresh mount with your fixed interval. After six ticks the screen must say 6, and each log must match what the screen showed at that moment.
New seal earned
The echo melted
Acharya’s Rule #8A closure remembers the render it was born in. Update from the previous value.
Every render gets its own count. A callback keeps the one from the render that made it.
setCount(c => c + 1) lets React hand you the latest state.
Need the value itself? Keep it in a ref, a dependency, or an Effect Event.