Skip to content

Instantly share code, notes, and snippets.

@vitalybe
Created July 9, 2019 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vitalybe/c1c1b6700dd760164d1f01225eb93bfd to your computer and use it in GitHub Desktop.
Save vitalybe/c1c1b6700dd760164d1f01225eb93bfd to your computer and use it in GitHub Desktop.
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