Created
March 21, 2021 21:34
-
-
Save florianmartens/3485a6b74bb6e66d4183f093ac53adfa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
commented
Mar 21, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment