function Clock(props) {
const [date, setDate] = useState(new Date());
useEffect(() => {
var timerID = setInterval(() => tick(), 1000);
return function cleanup() {
clearInterval(timerID);
};
});
function tick() {
setDate(new Date());
}
return (
<div>
<h2>It is {date.toLocaleTimeString()}.</h2>
</div>
);
}
Created
June 4, 2019 08:24
-
-
Save endiliey/b5f230c4cb6420641875612e25c3d4e1 to your computer and use it in GitHub Desktop.
react live testing
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment