Skip to content
Justice Tech School

Effect Cleanup

Return a function from an effect to clean up timers and listeners. React runs it before re-running the effect and on unmount.

Example
useEffect(() => {
  const id = setInterval(() => setT((t) => t + 1), 1000);
  return () => clearInterval(id);
}, []);

Exercise

Cleanup returns a ___.

return () => clearInterval(id) is a 

Quiz Test

What does the cleanup function do?

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