Recall & Review
beginner
What is the purpose of the dependency array in React's useEffect hook?
The dependency array tells React when to run the effect. React runs the effect only if one of the dependencies has changed since the last render.
Click to reveal answer
beginner
What happens if you pass an empty dependency array ([]) to useEffect?
The effect runs only once after the first render, similar to componentDidMount in class components.Click to reveal answer
beginner
What is the effect of omitting the dependency array in useEffect?
The effect runs after every render, which can cause performance issues or unwanted repeated actions.
Click to reveal answer
intermediate
Why should you include all variables used inside useEffect in its dependency array?
Including all variables ensures the effect updates correctly when those variables change, preventing bugs and stale data.
Click to reveal answer
intermediate
What can happen if you incorrectly specify dependencies in the dependency array?
The effect might not run when it should, or it might run too often, causing bugs or performance problems.
Click to reveal answer
What does an empty dependency array in useEffect mean?
✗ Incorrect
An empty array means the effect runs once after the component mounts.
If you omit the dependency array in useEffect, when does the effect run?
✗ Incorrect
Without the array, useEffect runs after every render.
Which of these should be included in the dependency array?
✗ Incorrect
All variables used inside the effect should be dependencies to keep the effect updated.
What problem can occur if dependencies are missing in the array?
✗ Incorrect
Missing dependencies can cause the effect to use outdated values.
How can you avoid infinite loops with useEffect?
✗ Incorrect
Correct dependencies prevent infinite loops caused by repeated effect runs.
Explain how the dependency array controls when useEffect runs in React.
Think about when React decides to run your effect based on the array.
You got /3 concepts.
Describe common mistakes with dependency arrays and how to avoid them.
Consider what happens if you forget to list variables or list wrong ones.
You got /3 concepts.