Recall & Review
beginner
What is the unmounting phase in React?
The unmounting phase is when a React component is removed from the UI and cleaned up before it disappears from the screen.
Click to reveal answer
beginner
Which React hook is used to run cleanup code during the unmounting phase?
The
useEffect hook with a cleanup function returned inside it runs during the unmounting phase.Click to reveal answer
intermediate
Why is cleanup important during the unmounting phase?
Cleanup stops memory leaks and removes event listeners or timers that are no longer needed when the component leaves the screen.
Click to reveal answer
intermediate
Show a simple example of cleanup in a React functional component.
Inside <code>useEffect(() => { const timer = setTimeout(...); return () => clearTimeout(timer); }, []);</code>, the returned function clears the timer when the component unmounts.Click to reveal answer
intermediate
What happens if you forget to clean up in the unmounting phase?
If cleanup is forgotten, your app may slow down or behave oddly because old timers or listeners keep running even after the component is gone.
Click to reveal answer
Which React hook lets you run code when a component unmounts?
✗ Incorrect
The cleanup function returned from useEffect runs when the component unmounts.
What is a common reason to use cleanup in the unmounting phase?
✗ Incorrect
Cleanup stops timers and removes event listeners to prevent memory leaks.
When does the cleanup function inside useEffect run?
✗ Incorrect
Cleanup runs before unmounting or before the effect runs again on dependency changes.
What could happen if you don't clean up in the unmounting phase?
✗ Incorrect
Not cleaning up can cause memory leaks and bugs from leftover processes.
Which of these is NOT a typical cleanup task during unmounting?
✗ Incorrect
Fetching data is not a cleanup task; it's usually done during mounting or updates.
Explain the unmounting phase in React and why cleanup is important.
Think about what happens when a component leaves the screen.
You got /3 concepts.
Describe how to use the useEffect hook to handle cleanup during unmounting.
Focus on the function returned inside useEffect.
You got /3 concepts.