RequestResult

type RequestResult<T> = object;

Reactive state for a one-shot request managed by useRequest.

Lifecycle: starts at fetching (or disabled when the source is null) and auto-fires on mount; transitions to success on success or error on failure. refresh() re-fires the request — while a re-fire is in flight, status returns to fetching and the stale data and/or error from the prior outcome remain populated (stale-while-revalidate).

Type Parameters

Type ParameterDescription
TThe value the underlying request resolves to.

Properties

data

data: T | undefined;

The most recent successful value, or undefined if no call has succeeded yet (or while disabled). Persists across subsequent refreshes (including failed ones) until a new success replaces it or reset() clears the store.


error

error: unknown;

The error from the most recent failed call, or undefined if no call has failed (or while disabled). Persists across subsequent refreshes until a new success clears it. May coexist with data when a successful attempt is followed by a failing one.


refresh

refresh: (options?) => void;

Re-fire the request. By default each call mints a fresh signal from getAbortSignal (if configured) and threads it through the underlying store's withSignal(signal).dispatch(). 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 fire with no caller-provided signal.

Stable reference.

Parameters

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

Returns

void


status

status: "disabled" | "error" | "fetching" | "success";

Lifecycle status as a discriminated string:

  • fetching: a request is in flight. data and error carry whatever stale content was available before this attempt (both undefined on the first attempt; either or both populated on a refresh after a prior outcome).
  • success: most recent call succeeded; data holds the result.
  • error: most recent call failed; error holds the reason.
  • disabled: source was null.

On this page