useTimestamp
Reactive Unix timestamp (ms) that auto-updates on every animation frame or interval
Returns a ReadonlyObservable<number> containing the current Unix timestamp in milliseconds, updated continuously via requestAnimationFrame (default) or a fixed interval.
Timestamp
Updates every frame via requestAnimationFrame.
Timestamp
1776588750404
import { import useTimestamp
useTimestamp } from "@usels/web";
function function Component(): JSX.Element
Component() { const const ts: any
ts = import useTimestamp
useTimestamp(); return <JSX.IntrinsicElements.div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div>{const ts: any
ts.any
get()}</JSX.IntrinsicElements.div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div>; // ts.get() → current Date.now(), updated every frame}import { createTimestamp } from "@usels/web";
function Component() { "use scope" const ts = createTimestamp(); return <div>{ts.get()}</div>; // ts.get() → current Date.now(), updated every frame}With offset
Section titled “With offset”import { observable, useTimestamp } from "@usels/web";
function Component() { const offset$ = observable(5000); const ts = useTimestamp({ offset: offset$ }); // ts.get() → Date.now() + 5000 — offset is reactive, updates each tick}import { createTimestamp, observable } from "@usels/web";
function Component() { "use scope" const ts = createTimestamp({ offset: observable(5000) }); // ts.get() → Date.now() + 5000 — offset is reactive, updates each tick}With callback
Section titled “With callback”import { useTimestamp } from "@usels/web";
function Component() { const ts = useTimestamp({ callback: (timestamp) => { console.log("tick:", timestamp); }, });}import { createTimestamp } from "@usels/web";
function Component() { "use scope" const ts = createTimestamp({ callback: (timestamp) => { console.log("tick:", timestamp); }, });}With pause/resume controls
Section titled “With pause/resume controls”import { useTimestamp } from "@usels/web";
function Component() { const { timestamp$, isActive$, pause, resume } = useTimestamp({ controls: true });}import { createTimestamp } from "@usels/web";
function Component() { "use scope" const { timestamp$, isActive$, pause, resume } = createTimestamp({ 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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options | TimestampOptions & { controls: true; } | - |
TimestampOptions
Section titled “TimestampOptions”Returns
Section titled “Returns”Pausable & { timestamp$: ObservablePrimitive<number>; }
| Name | Type | Description |
|---|---|---|
isActive$ | ReadonlyObservable<boolean> | - |
pause | Fn | - |
resume | Fn | - |
timestamp$ | ObservablePrimitive<number> | - |