1function Counter() {
2 const [count, setCount] = useState(0);
3
4 useEffect(() => {
5 const id = setInterval(() => {
6 setCount(count + 1);
7 }, 1000);
8 return () => clearInterval(id);
9 }, []);
10
11 return <div>{count}</div>;
12}
no lines flagged
#054PracticeEasy10 min · 50 XP
Missing Dependency in useEffect
A useEffect hook reads stale state because a dependency is missing from the array, causing the callback to close over an old value.
Flagged linesNo lines flagged yet
What's wrong?
Flag a line or write a note to submit.