Created
December 2, 2021 12:41
-
-
Save omas-public/c19ea039cda444937a55455a5d792c2e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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