0
0
Reactframework~5 mins

Unmounting phase in React - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AuseContext
BuseState
CuseEffect with a cleanup function
DuseMemo
What is a common reason to use cleanup in the unmounting phase?
ATo add new components
BTo fetch new data
CTo update the UI
DTo stop timers or remove event listeners
When does the cleanup function inside useEffect run?
AOnly when the component mounts
BBefore the component unmounts or before the effect runs again
CAfter every render
DNever
What could happen if you don't clean up in the unmounting phase?
AMemory leaks and unexpected behavior
BThe component will never mount
CThe app will crash immediately
DNothing happens
Which of these is NOT a typical cleanup task during unmounting?
AFetching data
BClearing timers
CRemoving event listeners
DCancelling subscriptions
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.