Skip to content

Instantly share code, notes, and snippets.

@omas-public
Created December 2, 2021 12:41
Show Gist options
  • Select an option

  • Save omas-public/c19ea039cda444937a55455a5d792c2e to your computer and use it in GitHub Desktop.

Select an option

Save omas-public/c19ea039cda444937a55455a5d792c2e to your computer and use it in GitHub Desktop.
import { useState, useEffect } from 'react'
const Clock = props => {
const [date, setDate] = useState(props.date)
const tick = () => setDate(new Date())
useEffect(() => {
const timerID = setInterval(tick, 1000)
return () => clearInterval(timerID)
}, [])
return (
<div>
<h1>Hello, world!</h1>
<h2>It is {date.toLocaleTimeString()}.</h2>
</div>
)
}
const App = props => {
return (
<>
<Clock date={new Date} />
</>
)
}
export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment