Skip to content

Instantly share code, notes, and snippets.

@NeoYo
Created September 17, 2021 13:16
Show Gist options
  • Save NeoYo/90e09baccda07e320bc260a55ec4d923 to your computer and use it in GitHub Desktop.
Save NeoYo/90e09baccda07e320bc260a55ec4d923 to your computer and use it in GitHub Desktop.
How to Use React useEffect - Counter Demo
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