useLiveMetrics
Call Signature
Section titled “Call Signature”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.
Parameters
Section titled “Parameters”deviceId
Section titled “deviceId”DeviceId | null | undefined
the device to read, or null/undefined for “no device”.
Returns
Section titled “Returns”LiveMetrics | null
the latest frame, or null.
Example
Section titled “Example”const metrics = useLiveMetrics(deviceId); // LiveMetrics | nullCall Signature
Section titled “Call Signature”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.
Type Parameters
Section titled “Type Parameters”T
the selected value type.
Parameters
Section titled “Parameters”deviceId
Section titled “deviceId”DeviceId | null | undefined
the device to read, or null/undefined for “no device”.
selector
Section titled “selector”(metrics) => T
maps a non-null frame to the selected value.
isEqual?
Section titled “isEqual?”(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.
Returns
Section titled “Returns”T | null
the selected value, or null when there is no device / no frame.
Example
Section titled “Example”const pace = useLiveMetrics(deviceId, (m) => m.pace.current); // number | nullconst watts = useLiveMetrics(deviceId, (m) => m.power.watts); // isolated re-renders