Last active
May 4, 2020 02:02
-
-
Save AZagatti/f18470cd622a516b3768e3ae98f2a8d7 to your computer and use it in GitHub Desktop.
useEffect
This file contains 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 React, { useState, useEffect } from "react"; | |
function App() { | |
const [count, setCount] = useState(0); | |
useEffect(() => { | |
const interval = setInterval(() => setCount(count + 1), 1000); | |
return () => { | |
clearInterval(interval) | |
} | |
}, [count]); | |
return ( | |
<div> | |
<h1>{count} segundos</h1> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment