useNow#

The current time as a reactive Date, updated every interval ms (default 1000). Cross-platform — import from @sigx/use.

TypeScript
import { computed } from 'sigx';
import { useNow } from '@sigx/use';

const now = useNow();
const clock = computed(() => now.value.toLocaleTimeString());

The Date is held by reference and replaced wholesale on each tick — Date is an exotic built-in sigx deliberately never proxies. Read now.value to get the current instant; don't mutate it in place.

The timer clears with the owning scope (component setup or the innermost effectScope()).

Controls form#

Pass { controls: true } to also get Pausable controls alongside the time. The return shape then becomes { now, pause, resume, isActive }:

TypeScript
import { useNow } from '@sigx/use';

const { now, pause, resume, isActive } = useNow({ controls: true, interval: 1000 });
pause(); // freeze the clock

Signature#

TypeScript
function useNow(): ReadSignal<Date>;
function useNow(options: UseNowOptions<true>): { now: ReadSignal<Date> } & Pausable;
function useNow(options: UseNowOptions<false>): ReadSignal<Date>;

Options#

OptionTypeDefaultDescription
intervalnumber1000Update period in ms.
controlsbooleanfalseAlso return pause/resume/isActive controls.

Returns#

CallReturns
useNow()ReadSignal<Date> — the current time, bare.
useNow({ controls: true }){ now: ReadSignal<Date> } & Pausable — the time plus pause/resume/isActive.

Platform: everywhere (setInterval).

See also#