[]previous and next page

Fetcher

A non-navigating loader or mutation with its own state.

A non-navigating loader or mutation with its own state. Keyed: the same key from two components is the same fetcher.

Import#

ts
import type { Fetcher } from "@shadow-js/dusk/client";

Signature#

ts
interface Fetcher {
  /** The key the fetcher was made with. */
  readonly key: string;
  /** The state of the last `load` or `submit`. */
  readonly state: Accessor<FetcherState>;
  /** The loader data of the last `load` (the page's matches), or the value of the last `submit`. */
  readonly data: Accessor<unknown>;
  /** The error of the last `load` or `submit`. */
  readonly error: Accessor<unknown>;
  /** The form data of the last `submit`, while it runs. */
  readonly formData: Accessor<FormData | undefined>;
  /** Fetches the page at `url` and keeps its loader data in `data`, without navigating. */
  load(url: string): Promise<void>;
  /** Submits to a server function stub without navigating; resolves when it has finished. */
  submit(target: StubTarget, input: FormData | unknown): Promise<void>;
}

Members#

Name Type Description
key readonly key: string The key the fetcher was made with.
state readonly state: Accessor<FetcherState> The state of the last load or submit.
data readonly data: Accessor<unknown> The loader data of the last load (the page's matches), or the value of the last submit.
error readonly error: Accessor<unknown> The error of the last load or submit.
formData readonly formData: Accessor<FormData | undefined> The form data of the last submit, while it runs.
load load(url: string): Promise<void> Fetches the page at url and keeps its loader data in data, without navigating.
submit submit(target: StubTarget, input: FormData | unknown): Promise<void> Submits to a server function stub without navigating; resolves when it has finished.