import React from "react";
const Clock = () => {
const [clock, setClock] = React.useState("");
const getTime = () => {
const date = new Date();
const hours = date.getHours();
let minutes = date.getMinutes();
let sec = date.getSeconds();
let currentTime = `${hours < 10 ? `0${hours}` : hours}:${
minutes < 10 ? `0${minutes}` : minutes
}:${sec < 10 ? `0${sec}` : sec}`;
setClock(currentTime);
};
React.useEffect(() => {
setInterval(getTime, 1000);
});
return (
<div className="clock">
<h1 className="clock__time">{clock}</h1>
</div>
);
};
export default Clock;