useTimestamp
Returns a ReadonlyObservable<number> containing the current Unix timestamp in milliseconds, updated continuously via requestAnimationFrame (default) or a fixed interval.
Timestamp: 1772791259743
Updates every frame via requestAnimationFrame.
import { import useTimestamp
useTimestamp } from "@usels/web";
const const ts: any
ts = import useTimestamp
useTimestamp();// ts.get() → current Date.now(), updated every frameWith offset
Section titled “With offset”import { import useTimestamp
useTimestamp } from "@usels/web";import { function observable<T>(): Observable<T | undefined> (+2 overloads)
observable } from "@legendapp/state";
const const offset$: any
offset$ = observable<unknown>(value: Promise<unknown> | (() => unknown) | unknown): any (+2 overloads)
observable(5000);const const ts: any
ts = import useTimestamp
useTimestamp({ offset: any
offset: const offset$: any
offset$ });// ts.get() → Date.now() + 5000 — offset is reactive, updates each tickWith callback
Section titled “With callback”import { import useTimestamp
useTimestamp } from "@usels/web";
const const ts: any
ts = import useTimestamp
useTimestamp({ callback: (timestamp: any) => void
callback: (timestamp: any
timestamp) => { any
console.any
log("tick:", timestamp: any
timestamp); },});With pause/resume controls
Section titled “With pause/resume controls”import { import useTimestamp
useTimestamp } from "@usels/web";
const { const timestamp$: any
timestamp$, const isActive$: any
isActive$, const pause: any
pause, const resume: any
resume } = import useTimestamp
useTimestamp({ controls: boolean
controls: true });Reactive offset
Section titled “Reactive offset”offset is read on every tick inside the update loop, so changing it (via Observable) takes effect on the next frame without restarting the scheduler.
Type Declarations
Section titled “Type Declarations”export interface UseTimestampOptions<Controls extends boolean = false> { controls?: Controls; offset?: number; interval?: "requestAnimationFrame" | number; callback?: (timestamp: number) => void;}export declare function useTimestamp(options?: UseTimestampOptions<false>): ReadonlyObservable<number>;export declare function useTimestamp(options: UseTimestampOptions<true>): { timestamp$: ReadonlyObservable<number>;} & Pausable;Source
Section titled “Source”Contributors
Section titled “Contributors”- tigerwest
Changelog
Section titled “Changelog”a7392ab2026-03-06 - feat(core,browser): add sync strategy hooks (tigerwest)