Skip to content

Instantly share code, notes, and snippets.

@AZagatti
Last active May 4, 2020 02:02
Show Gist options
  • Save AZagatti/f18470cd622a516b3768e3ae98f2a8d7 to your computer and use it in GitHub Desktop.
Save AZagatti/f18470cd622a516b3768e3ae98f2a8d7 to your computer and use it in GitHub Desktop.
useEffect
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