useNow
A React Hook that tracks the current date.
Demo
SourceNow: 2024-12-06 08:07:11:228
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