← React Foundations
14 / 25
Lesson 14 — useEffect: timers
The dependency array
The second argument of useEffect is the dependency array: React re-runs the effect whenever a value in it changes (first running the old cleanup). [] means "run once"; [running] means "run again every time running changes". If the effect reads a state value but does not list it, it keeps seeing the old value.
useEffect(() => {
document.title = "Count: " + count;
}, [count]); // re-runs when count changes
Why it matters: a wrong dependency array is the number-one useEffect bug — effects that never update, or run forever.
Want it another way?
Task
Fix the dependency array so Start actually starts the timer: after clicking Start, the heading counts 1s, 2s…
Test your knowledge
A quick 3-question quiz on this lesson — instant feedback.