useEffect Dependencies
Question
What does the dependency array in useEffect do?
Hint
Empty array runs once; no array runs every render.
Explanation
The dependency array is the second argument to useEffect. It controls when the effect re-runs. An empty array [] runs the effect only once after mount. No array runs it after every render. Specific dependencies [a, b] run it when a or b changes. Missing dependencies cause stale closures; extra dependencies cause unnecessary runs. The eslint-plugin-react-hooks exhaustive-deps rule helps catch missing dependencies.
Related Resources
Related Lessons
- useEffect
Learn useEffect.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.