hooks/useClock
import { … } from 'zidane-ui'ui/src/hooks/useClock.ts
Functions#
useClockFunction#
Re-renders the caller every intervalMs while active (and when the window shows again). Every reader of one
length shares one interval.
function useClock(intervalMs: number, active?: boolean): numberParameters
| Name | Type | Default | Description |
|---|---|---|---|
| intervalMs | number | How often: | |
| active? | boolean | true | Whether anything on screen moves. Off: no interval, no re-render. |
Returns
numberThe time to measure from: the last tick's, or when the caller started reading when that is later. Under a
ClockStartContext, its start until the clock's first tick after the page is hydrated.
useClockReaderFunction#
Reads the time on the clock useClock answers with, whenever it is called: the page's under a
ClockStartContext (its start until the page is hydrated), else the machine's. For a
time read once (when a card opened) or on a component's own timer.
function useClockReader(): () => numberReturns
() => numberThe reader. A new one once the page is hydrated: a timer started with the old one starts again.
Constants#
ClockStartContextConstant#
The time a server drew the page at, in ms: what useClock answers on that server and while the browser
hydrates its HTML (from then on, the machine's clock: what happens on the page is stamped by it). The page sends
it with its markup and provides the same value on both sides. null (the default): the machine's clock.
const ClockStartContext: Context<number | null>