The second argument passed to useEffect is the Dependency Array. This array tells React exactly which state variables or props the effect relies on.
React evaluates the dependency array using shallow equality (Object.is) before every re-render to determine whether the effect callback should run again.
[] (Run on Mount Only)[dep1, dep2] (Run on Change)Every reactive value referenced inside your effect callback MUST be included in the dependency array.
A "reactive value" includes:
Because React checks dependencies using reference equality (Object.is), defining objects or functions inside your component body can trigger unwanted effect runs:
useEffect(() => { ... })?useEffect dependency array?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| The useEffect Hook for Side Effects | Cleanup Functions in useEffect |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.