Skip to content

Instantly share code, notes, and snippets.

@YKalashnikov
Last active April 14, 2019 20:40
Show Gist options
  • Save YKalashnikov/b5ad6cce1e5ac18a68e94958719dc3cd to your computer and use it in GitHub Desktop.
Save YKalashnikov/b5ad6cce1e5ac18a68e94958719dc3cd to your computer and use it in GitHub Desktop.
function CounterHooks() {
const [count, setCount] = useState(0);
const [time, setTime] = useState(new Date())
// 🐢 look here.
useEffect(() => {
console.log("useEffect first timer here.")
}, [count])
const handleClick = () => {
setCount(count + 1);
setTime(new Date())
}
return (
<div>
<h3 className="center">Welcome to the Counter of Life </h3>
<button className="center-block"
onClick={handleClick}>{count}</button>
<p className="center"> at: {`${time.getHours()} : ${time.getMinutes()} : ${time.getSeconds()}`}</p>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment