This component has two separate effects. One logs when the count changes. The other logs when the name changes. This keeps the logic clear and easy to manage.
A. The first useEffect should not have a dependency array.
B. You cannot use two useEffect hooks in one component.
C. The second useEffect has no dependency array, so it runs after every render.
D. The console.log statements are invalid inside useEffect.
Solution
Step 1: Check dependency arrays in useEffect hooks
The first useEffect has a dependency array [value], so it runs only when value changes.
Step 2: Analyze second useEffect without dependency array
The second useEffect has no dependency array, so it runs after every render, which might be unintended.
Final Answer:
The second useEffect has no dependency array, so it runs after every render. -> Option C
Quick Check:
Missing deps means effect runs every render [OK]
Hint: Always add dependency array to control effect runs [OK]
Common Mistakes:
Thinking multiple useEffects are not allowed
Ignoring missing dependency arrays
Believing console.log is invalid inside useEffect
5. You want to fetch user data when the component mounts and also update the document title whenever the user's name changes. How should you organize your useEffect hooks?
hard
A. Use two separate useEffect hooks: one with empty deps for fetch, one with [user.name] for title.
B. Use one useEffect to fetch data and update title together with both dependencies.
C. Use one useEffect with no dependencies to do both tasks on every render.
D. Use two useEffect hooks both with empty dependency arrays.
Solution
Step 1: Separate concerns with multiple useEffect hooks
Fetching data should happen once on mount, so useEffect with empty dependency array is best.
Step 2: Update document title when user.name changes
Use a separate useEffect with [user.name] dependency to update title only when name changes.
Final Answer:
Use two separate useEffect hooks: one with empty deps for fetch, one with [user.name] for title. -> Option A
Quick Check:
Separate effects by task and dependencies [OK]
Hint: Separate effects by when and why they run [OK]
Common Mistakes:
Combining unrelated tasks in one effect
Missing dependencies causing stale updates
Running fetch on every render unintentionally
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.