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.

RaidenEvery render of Kai’s timer is a flash of lightning: one instant, frozen. Start the timer and listen to what the interval keeps repeating.
08Seal 08
kai.app/timer
Seconds on this page0
Console
    Raiden’s renders each render keeps its own count

      1 · 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);
      }, []);
      Ticks 0Screen shows 0Renders 1
      Each render is a snapshot

      Every render gets its own count. A callback keeps the one from the render that made it.

      Update from the previous value

      setCount(c => c + 1) lets React hand you the latest state.

      Read through a ref

      Need the value itself? Keep it in a ref, a dependency, or an Effect Event.