Skip to content

Instantly share code, notes, and snippets.

@gisderdube
Created February 6, 2019 13:10
Show Gist options
  • Select an option

  • Save gisderdube/7f98d8efc7e7095807d6fa6605e4e30e to your computer and use it in GitHub Desktop.

Select an option

Save gisderdube/7f98d8efc7e7095807d6fa6605e4e30e to your computer and use it in GitHub Desktop.
import React, { useEffect, useState } from 'react'
function Counter() {
const [count, setCount] = useState(0)
useEffect(() => {
const interval = setInterval(() => {
setCount(count + 1)
}, 1000)
return () => {
clearInterval(interval)
}
}, [])
return (
<div>
Current count is: {count}
</div>
)
}
export default Counter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment