Skip to main content
React Output Prediction Medium +20 XP

useEffect Dependency

When does this effect run?

ReactRead-only
useEffect(() => {
  fetchData();
}, [userId]);

What is the output?

Show answer and explanation

Answer: When userId changes

useEffect with [userId] in the dependency array runs after every render where userId has changed.

Hint: The dependency array controls when the effect runs.

What this challenge tests

Output Prediction in React: hooks, useEffect.

Related challenges