Complete useEffect Cleanup
Fill in the Blank Medium
Question
Fill in the blank to clean up the interval on unmount.
Code
useEffect(() => {
const id = setInterval(tick, 1000);
_____ () => clearInterval(id);
}, []);
Hint
The cleanup function must be returned from the effect.
Explanation
The cleanup function must be returned from the useEffect callback. React calls it before the next effect or on unmount. Returning the cleanup prevents memory leaks from orphaned intervals.
Related Resources
Related Lessons
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.