A. useEffect with setUser dependency causing repeated fetch
B. useEffect without dependencies fetching every render
C. useEffect with user dependency causing infinite fetch
D. useEffect with empty array to fetch once on mount
Solution
Step 1: Understand useEffect dependencies for fetching
Empty array [] runs effect once on mount; no dependencies cause repeated fetches.
Step 2: Analyze each option
The useEffect with an empty dependency array fetches data only once on mount. Without any dependency array, the effect runs after every render. Depending on user causes an infinite loop since updating user triggers re-renders. Depending on setUser runs only once because setUser is stable, but it is unnecessary and may cause ESLint warnings.
Final Answer:
useEffect with empty array to fetch once on mount -> Option D
Quick Check:
Empty [] means fetch once on mount [OK]
Hint: Empty array in useEffect fetches once on mount [OK]
Common Mistakes:
Leaving out dependency array causes infinite fetch
Using state as dependency causing loops
Misunderstanding stable functions as dependencies
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.