Created
July 9, 2019 20:16
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
function App({ date }) { | |
const [currentDate, setCurrentDate] = useState(new Date()); | |
const [count, setCount] = useState(0); | |
function updateCount(byValue) { | |
setCount(count + byValue); | |
setCurrentDate(new Date()); | |
} | |
function formatDate() { | |
const hour = date.getHours(); | |
const minute = date.getMinutes(); | |
const second = date.getSeconds(); | |
return (`${hour}:${minute}:${second}`); | |
} | |
const prettyDate = formatDate(); | |
return ( | |
<div className="App"> | |
<h1>Hello CodeSandbox</h1> | |
<h2> | |
You clicked {count} times, last time at {prettyDate}! | |
</h2> | |
<button onClick={() => updateCount(-1)}>Decrement</button> | |
<button onClick={() => updateCount(1)}>Increment</button> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment