import { useEffect, useState } from "react";
function Clock() {
const [now, setNow] = useState(Date.now());
useEffect(() => {
const id = setInterval(() => setNow(Date.now()), 1000);
return () => clearInterval(id);
}, []);
return <span>{now}</span>;
}an interval with cleanup