Skip to main content

Hooks

React hooks that connect your components to live device data. All hooks require your app to be wrapped in RelayProvider.

useRelayApp()

Access the raw App SDK instance.

import { useRelayApp } from "@relay-x/ui";

const app = useRelayApp(); // RelayAppInstance | null

useRelayConnection()

Access the App SDK instance and connection status.

import { useRelayConnection } from "@relay-x/ui";

const { app, isConnected, error } = useRelayConnection();
ReturnTypeDescription
appobject | nullThe App SDK instance
isConnectedbooleanWhether the SDK is connected
errorstring | nullError message if connection failed (e.g., auth_failed)

useRelayTimeSeries()

Stream historical and/or real-time telemetry data for a device.

import { useRelayTimeSeries } from "@relay-x/ui";

const { data, isLoading, error } = useRelayTimeSeries({
deviceIdent: "sensor_01",
metrics: ["temperature", "humidity"],
mode: "both",
timeRange: {
start: Date.now() - 3600000,
end: Date.now(),
},
});

Options

OptionTypeDescription
deviceIdentstringThe device identifier
metricsstring[]Metrics to subscribe to
modestring"historical", "realtime", or "both"
timeRangeobject{ start: number, end: number } — timestamps in ms
maxPointsnumber(optional) Maximum data points to keep. Default: 10000

Modes

ModeBehavior
"historical"Fetches data once for the given time range. No live updates.
"realtime"Streams live data only. No historical data.
"both"Fetches historical data first, then streams live updates. New data is merged in.

Return

ReturnTypeDescription
dataDataPoint[]Array of data points with merged metrics
isLoadingbooleantrue while fetching historical data
errorError | nullError if the fetch or stream failed

useRelayLatest()

Get the most recent value for a single metric. Fetches the latest and subscribes to live updates. Returns a RelayDataPoint that can be passed directly to any component's data prop.

import { useRelayLatest } from "@relay-x/ui";

const latest = useRelayLatest({
deviceIdent: "sensor_01",
metric: "temperature",
timeRange: {
start: Date.now() - 86400000,
end: Date.now(),
},
});

// Pass directly to a component
<NeedleGauge data={latest} min={0} max={100} />

Options

OptionTypeDescription
deviceIdentstringThe device identifier
metricstringThe metric name
timeRangeobject{ start: number, end: number } — timestamps in ms

Return (RelayDataPoint)

ReturnTypeDescription
valuenumber | nullThe latest metric value
timestampnumber | nullWhen the value was recorded (ms)
isLoadingbooleantrue while fetching
errorError | nullError if the fetch or stream failed

Components that accept a data prop (NeedleGauge, ArcGauge, ProgressBar, StatCard, StatCardWithGraph) expect this exact shape.

useRelayPresence()

Track whether a device is online or offline.

import { useRelayPresence } from "@relay-x/ui";

const { online, lastEvent, isLoading, error } = useRelayPresence("sensor_01");

Return

ReturnTypeDescription
onlineboolean | nulltrue if online, false if offline, null if unknown
lastEventobject | nullLast presence event with device_ident and event type
isLoadingbooleantrue while initial presence is being determined
errorError | nullError if the presence subscription failed