Skip to main content
Version: 0.1.2

Type Alias: FetchStateValue

Imported from @react-logic/utils

FetchStateValue<T> = { failed: false; idle: true; loading: false; } | { failed: false; idle: false; loading: true; } | { failed: false; idle: false; loading: false; result: T; status: number; } | { error: Error; failed: true; idle: false; loading: false; status?: number; }

The value carried by a fetchState / fetchState.callable signal. A discriminated union with four variants — branch on idle / loading / failed, then read result / error / status.

const s = data();
if (s.idle) return <button>Start</button>; // callable, never fired
if (s.loading) return <Spinner />;
if (s.failed) return <Error message={s.error.message} status={s.status} />;
return <List items={s.result} httpStatus={s.status} />;

idle — only emitted by fetchState.callable before its first .fetch(...). Reactive fetchState skips this state: the build callback fires immediately, so the initial value is loading.

status — HTTP status code. Present on success. Present on failed only when the request reached a response (parse threw, non-2xx default-parse rejected, etc.). Absent on pure network failures (CORS, DNS, fetch threw before a response existed).

Type Parameters

T

T

The parsed response type.