Created
September 17, 2021 13:16
-
-
Save NeoYo/90e09baccda07e320bc260a55ec4d923 to your computer and use it in GitHub Desktop.
How to Use React useEffect - Counter Demo
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
function Counter() { | |
const [count, setCount] = useState(0); | |
useEffect(() => { | |
const id = setInterval(() => { | |
setCount(c => c + 1); | |
}, 1000); | |
}, []); | |
return <h1>{count}</h1>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment