snippet
Updating state not when Using React state Hook without setInterval function
const MyApplication = () => {
const [count, setCount] = React.useState(0);
React.useEffect(() => {
const timer = window.setInterval(() => {
setCount(count => count + 1)
}, 1000);
return () => {
window.clearInterval(timer);
};
}, []);
return (
<div>{count}</div>
);
}
Related snippets |
---|