SubscriptionResult

type SubscriptionResult<T> = object;

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 ParameterDescription
TThe unwrapped value type of the subscription notification.

Properties

data

data: T | undefined;

The latest value. undefined on the first load or when disabled. On loading after a prior outcome, on error, and on a subsequent reconnect, holds the last known value (if one ever arrived) so UIs can show stale data rather than flashing to blank.


error

error: unknown;

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

reconnect: (options?) => void;

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

ParameterType
options?{ abortSignal?: AbortSignal; }
options.abortSignal?AbortSignal

Returns

void


slot

slot: Slot | undefined;

The slot data was observed at — lifted from context.slot from a SolanaRpcResponse. Follows data: once a notification has arrived, slot stays pinned to its data across subsequent loading and error transitions. undefined before the first notification arrives (initial loading, disabled, or on the server), and always undefined for subscriptions that emit raw, non-SolanaRpcResponse values.


status

status: "disabled" | "error" | "loaded" | "loading";

Lifecycle status as a discriminated string:

  • loading: a connection is in progress. On the first connection, data and error are undefined. After a reconnect, data and error hold the last known values from the previous connection (stale-while-revalidate).
  • loaded: at least one notification has arrived.
  • error: the subscription failed; data holds the last known value (if any).
  • disabled: source was null — no subscription was opened.

On this page