(intervalMs: number)
| 11 | * frame index) from the shared clock. |
| 12 | */ |
| 13 | export function useAnimationTimer(intervalMs: number): number { |
| 14 | const clock = useContext(ClockContext) |
| 15 | const [time, setTime] = useState(() => clock?.now() ?? 0) |
| 16 | |
| 17 | useEffect(() => { |
| 18 | if (!clock) return |
| 19 | |
| 20 | let lastUpdate = clock.now() |
| 21 | |
| 22 | const onChange = (): void => { |
| 23 | const now = clock.now() |
| 24 | if (now - lastUpdate >= intervalMs) { |
| 25 | lastUpdate = now |
| 26 | setTime(now) |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | return clock.subscribe(onChange, false) |
| 31 | }, [clock, intervalMs]) |
| 32 | |
| 33 | return time |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Interval hook backed by the shared Clock. |
nothing calls this directly
no outgoing calls
no test coverage detected