Loading

Quipoin Menu

Learn • Practice • Grow

react / useEffect Hook in React
mcq
Direction: Choose the correct option

Q1.

What is the useEffect hook used for?
A. Handling side effects in functional components
B. Creating refs
C. Optimizing renders
D. Managing state
Direction: Choose the correct option

Q2.

By default, when does the effect function in useEffect run?
A. Only once after initial render
B. Only when dependencies change
C. Never
D. After every completed render (including first)
Direction: Choose the correct option

Q3.

How do you make useEffect run only once (on mount)?
A. Pass an empty dependency array []
B. Use useMountEffect hook
C. Pass a non-empty array
D. Omit the second argument
Direction: Choose the correct option

Q4.

What is the purpose of the cleanup function in useEffect?
A. To memoize values
B. To handle errors
C. To update state
D. To cancel subscriptions or timers before the component unmounts or before the next effect runs
Direction: Choose the correct option

Q5.

Which of the following is a correct way to use useEffect for fetching data?
A. useEffect(() => { async function fetchData() { await ... }; fetchData(); }, []);
B. Both B and C
C. useEffect(async () => { await fetch(...); }, []);
D. useEffect(() => { fetch(...); }, []);