Skip to content
Rung

05/12

No. 05Medium15 min

Effects: The Ghost Timer

Mission

Manage the lifecycle of side effects and write cleanup functions so your app never leaks memory.

Tasks

  1. 1

    Create a state for the seconds, starting at 0.

  2. 2

    Write a useEffect that starts a setInterval ticking every 1000ms.

  3. 3

    Inside the interval, log 'Tick...' so you can watch it in the console.

  4. 4

    Update the seconds with the functional form of the setter.

  5. 5

    Return a cleanup function that stops the interval when the component unmounts.