Skip to content

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 frame
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 tick
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
);
},
});
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 });

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.

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;

View on GitHub

  • tigerwest
  • a7392ab 2026-03-06 - feat(core,browser): add sync strategy hooks (tigerwest)