Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save florianmartens/3485a6b74bb6e66d4183f093ac53adfa to your computer and use it in GitHub Desktop.
Save florianmartens/3485a6b74bb6e66d4183f093ac53adfa to your computer and use it in GitHub Desktop.
import { useState, useEffect } from "react";
export default function App() {
const initalState = 0;
const [count, setCount] = useState(initalState);
useEffect(() => {
const interval = setInterval(() => {
setCount(count + 1);
}, 1000);
return () => clearInterval(interval)
}, [count]);
return (
<div className="App">
<h1>The current count is:</h1>
<h2>{count}</h2>
</div>
);
}
@prince582
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment