Data and Host State Hooks
This page focuses on runtime hooks most widgets use.
Data Hooks
useStream
Use for subscription style updates from GraphQL streams.
Returns:
status(idle,loading,ok,failed)dataerrorretry()
usePolling
Use for interval based refresh logic, usually driven by useWidgetRefreshRate(instanceId).
useMutation
Use for write operations with stable execute semantics.
useStreamHistory
Use when you need a rolling history window from a selector.
Host State Hooks
useBrush: read/set global brush expressionuseVariables: read/set dashboard variable mapuseHostVariables: read resolved host-level variables (read-only; from the host environment, not dashboard config)useWorkspace: read/set active workspaceuseUserTimeRangeanduseEffectiveTimeRange: time selectionuseWidgetLayout: host layout measurementsuseThemeMode: light/dark mode awarenessuseReplayMode: detect whether the dashboard is in replay/offline modeuseRoleLevelAccess: read the user’s current role level for conditional rendering or feature gatinguseWidgetConfigPersistence: persist and restore widget-local state across page reloads (separate from schema config)
Practical Pattern: Live + Polling Fallback
components-table-widget exposes useLiveData in schema and supports both modes:
useLiveData = true: stream updatesuseLiveData = false: polling on dashboard refresh cadence
This gives users control when a backend stream is unavailable or too expensive.
Practical Pattern: Variable + Workspace Interaction
grid-widget integrates click actions with host state:
On square click, optionally set a selected variable value
Optionally switch workspace
Formatting uses
INPUT_FORMATED_SCHEMA_TYPEand runtime formatting helpers
Keep this behavior explicit in schema descriptions so users understand side effects.