Skip to content
Mosaic
On this page

useNow

Returns the current time as a Date. Starts from MosaicProvider's mount time when inside one, and only ticks when updateInterval is set.

Use for

  • any current time read during render
  • a countdown or relative time that ticks
  • stopping a tick at a deadline with until

Practices

GuidancePractice
DoPass until for a countdown, so the interval stops once the deadline passes.
Don’tCall new Date() or Date.now() during render. Use this hook instead.

Options

PropTypeDescription
updateIntervalnumberMilliseconds between ticks. No ticking when unset.
untilnumberA timestamp in milliseconds. Ticking stops once now reaches it.

Examples

Tick every second until a deadline

TSX
const now = useNow({ updateInterval: 1000, until: expiresAt });