useNow

A React Hook that tracks the current date.

Demo

Source
Now:
2024-09-11 09:07:25:035
isActive:
false
Now:
1726045645035
Update count:
0

Usage

See API for more details.

Source

Click links below to view source on GitHub.

API

const now = useNow(options) const { now, ...controls } = useNow({ controls: true, ...otherOptions })

Options

export type UseNowOptions<Controls extends boolean> = UseIntervalFnOptions & { /** * Expose more controls * * @defaultValue false */ controls?: Controls /** * Update interval in milliseconds, or use requestAnimationFrame * * @defaultValue requestAnimationFrame */ interval?: UseIntervalFnInterval /** * Callback on each update */ callback?: (now: Date) => void }

Returns

Retuerns contain Pausable instance that can be paused, resumed.

See Pausable for more details.

If controls is true, returns an object with now and Pausable Instance, else returns the current Date instance.

export type UseNowReturns<Controls extends boolean> = Controls extends true ? { now: Date } & Pausable : Date