function Counter() { const [count, setCount] = React.useState(0); React.useEffect(() => { console.log(999); // not executed repeatedly const id = setInterval(() => { // setCount(count+1); // count always 0 here. works if [count] is the dependency. setCount(c => c + 1); // ✅ This doesn't depend on `count` variable outside }, 1000); return () => clearInterval(id); }, []); // ✅ Our effect doesn't use any variables in the component scope return

{count}

;}