SubscriptionResult
Reactive state for a subscription managed by useSubscription (and other stream-store hooks built on top of it).
Lifecycle: starts at loading (or disabled when the source is null) and opens the
underlying stream on mount; transitions to loaded on the first notification or error on
failure. reconnect() re-opens the stream — while a reconnect is in flight, status returns
to loading and the stale data and/or error from the prior connection remain populated
(stale-while-revalidate).
Type Parameters
| Type Parameter | Description |
|---|---|
T | The notification type emitted by the underlying source. |
Properties
data
The latest notification. undefined on the first load and while disabled. On loading
after a prior outcome, on error, and on a subsequent reconnect, holds the last
received notification.
error
Error from the subscription, or undefined. On loading after a prior error, holds the
stale error so UIs can keep showing the failure context (e.g. a banner) while the
reconnect is in flight. A subsequent loaded clears it.
reconnect
Re-open the stream. By default each call mints a fresh signal from getAbortSignal (if
configured) and threads it through the underlying store's withSignal(signal).connect().
Pass { abortSignal } to override the configured factory for just this attempt. Pass
{ abortSignal: undefined } to opt out of the factory entirely for this attempt and open
with no caller-provided signal.
Stable reference. Safe to put in onClick handlers or effect deps — typically wired up
to a "Reconnect" button when status === 'error'. Calls store.connect() under the
hood, so it always (re)opens the stream regardless of current status; the bridge
transitions back through loading while preserving stale data and error.
Parameters
| Parameter | Type |
|---|---|
options? | { abortSignal?: AbortSignal; } |
options.abortSignal? | AbortSignal |
Returns
void
status
Lifecycle status as a discriminated string:
loading: a connection is in progress. On the first connection,dataanderrorareundefined. After a reconnect,dataanderrorhold the last known values from the previous connection (stale-while-revalidate).loaded: at least one notification has arrived.error: the subscription failed;dataholds the last known value (if any).disabled: source wasnull— no subscription was opened.