Spaces:
Running
Running
File size: 322 Bytes
6f5f15e | 1 2 3 4 5 6 7 8 9 10 11 | import { useEffect, useState } from 'react';
export function useNow(intervalMs = 1000): number {
const [now, setNow] = useState(() => Date.now());
useEffect(() => {
const id = window.setInterval(() => setNow(Date.now()), intervalMs);
return () => window.clearInterval(id);
}, [intervalMs]);
return now;
}
|