Reactjs – Use up-to-date state variable in `useEffect`
Javascript binds variables to functions as they are created, which can cause 'dangling' out-of-date values to be used in useEffect. function Counter() { var [count, setCount] = useState(1); useEffect(() => { var timeout = setInterval(() => setCount(count => count+1), 1000);…