Skip to content

useLiveMetrics

useLiveMetrics(deviceId): LiveMetrics | null

Defined in: console-sdk/src/react/hooks/useLiveMetrics.ts:81

Reads the whole latest LiveMetrics frame for a device (SDK_PLAN.md §3.7 row 12, first overload). Returns null when deviceId is null/undefined, or when the device has no committed frame yet (or has been reset at a session boundary). While mounted with a real deviceId, the hook retains the device’s monitoring stream (refcounted); it releases on unmount or when the id changes.

Note: the whole-frame form re-renders on every committed frame — the coalesced store commits at most once per animation frame, so this is bounded, but for tiles prefer the selector overload so a change to one field does not re-render a tile bound to another.

DeviceId | null | undefined

the device to read, or null/undefined for “no device”.

LiveMetrics | null

the latest frame, or null.

const metrics = useLiveMetrics(deviceId); // LiveMetrics | null

useLiveMetrics<T>(deviceId, selector, isEqual?): T | null

Defined in: console-sdk/src/react/hooks/useLiveMetrics.ts:110

Reads a selected value from the latest LiveMetrics frame for a device (SDK_PLAN.md §3.7 row 12, second overload). The selector receives a non-null frame — the hook short-circuits the null case, so the m?. dance is gone — and re-renders only when the selected value changes (guarded by isEqual, defaulting to Object.is). Returns null when deviceId is null/undefined or the device has no committed frame yet; the selector is never called in that case.

T

the selected value type.

DeviceId | null | undefined

the device to read, or null/undefined for “no device”.

(metrics) => T

maps a non-null frame to the selected value.

(a, b) => boolean

optional equality for derived selections (arrays/objects); when it reports equality the previous selection is kept by reference and no re-render happens. Defaults to Object.is semantics.

T | null

the selected value, or null when there is no device / no frame.

const pace = useLiveMetrics(deviceId, (m) => m.pace.current); // number | null
const watts = useLiveMetrics(deviceId, (m) => m.power.watts); // isolated re-renders