Tsallaka zuwa abun ciki
Justice Tech School

Effect Cleanup

Return a function to clean up timers and listeners.

Example
useEffect(() => {
  const id = setInterval(() => console.log("tick"), 1000);
  return () => clearInterval(id);
}, []);

Exercise

Cleanup function.

return () => (id);

Quiz Test

When does cleanup run?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.