Loading

Quipoin Menu

Learn • Practice • Grow

react / Cleanup in useEffect
mcq
Direction: Choose the correct option

Q1.

How do you perform cleanup in useEffect?
A. By using useCleanup hook
B. By calling a cleanup function manually
C. By passing a second argument
D. By returning a function from the effect
Direction: Choose the correct option

Q2.

When is the cleanup function called?
A. Never
B. Only when the component unmounts
C. After every render
D. Before the effect runs again (on next render) and on unmount
Direction: Choose the correct option

Q3.

Which scenario typically requires cleanup?
A. Updating state
B. Fetching data
C. Setting up a subscription or timer
D. Rendering JSX
Direction: Choose the correct option

Q4.

What will the following code do? useEffect(() => { const timer = setInterval(() => {}, 1000); return () => clearInterval(timer); }, []);
A. Set an interval that is cleared on unmount
B. Set an interval that runs forever
C. Set an interval that clears after each render
D. Cause an error
Direction: Choose the correct option

Q5.

If an effect has no cleanup function, what happens?
A. The component may crash
B. It's a syntax error
C. No cleanup is performed
D. React adds a default cleanup