[]previous and next page

ResourceOptions

Options of useResource.

Options of useResource.

Import#

ts
import type { ResourceOptions } from "@shadow-js/core";

Signature#

ts
interface ResourceOptions<T> {
  /**
   * Value shown before the first fetch settles. With it the resource never reads as `"pending"`: the
   * first fetch still runs, as a refresh (`"refreshing"`, `info.refetching` true), and never
   * suspends. A key that is present with the value `undefined` counts as given.
   * @default No initial value: the first fetch reads as `"pending"` and suspends its readers.
   */
  initialValue?: T;
  /**
   * The key that matches the value a server render recorded with the resource that hydrates it.
   * Give one when the creation order may differ between server and client.
   * @default undefined (a key is generated from the resource's position in the render)
   */
  key?: string;
  /**
   * On the server, the streamed response holds its first flush until this resource settles, so its value
   * is in the shell (the first chunk) and not in a later chunk behind a fallback. A resource that
   * rejects does not hold the stream: its fallback stays. Only resources created while the shell renders
   * hold it; a resource created later, by a streamed boundary, streams as usual. Other renderers
   * (`renderToString`, `renderToStringAsync`) already wait for every resource, so the option has no
   * effect there. Matches Solid's option of the same name.
   * @default false
   */
  deferStream?: boolean;
  /**
   * Label shown by devtools next to the resource's state changes. It has no effect on caching or on
   * the server key (use `key` for that) and costs nothing in production builds, where devtools reporting
   * is removed.
   * @default undefined (the resource is unnamed)
   */
  name?: string;
}

Members#

Name Type Description
T T
initialValue? initialValue?: T Value shown before the first fetch settles. With it the resource never reads as "pending": the first fetch still runs, as a refresh ("refreshing", info.refetching true), and never suspends. A key that is present with the value undefined counts as given.
key? key?: string The key that matches the value a server render recorded with the resource that hydrates it. Give one when the creation order may differ between server and client.
deferStream? deferStream?: boolean On the server, the streamed response holds its first flush until this resource settles, so its value is in the shell (the first chunk) and not in a later chunk behind a fallback. A resource that rejects does not hold the stream: its fallback stays. Only resources created while the shell renders hold it; a resource created later, by a streamed boundary, streams as usual. Other renderers (renderToString, renderToStringAsync) already wait for every resource, so the option has no effect there. Matches Solid's option of the same name.
name? name?: string Label shown by devtools next to the resource's state changes. It has no effect on caching or on the server key (use key for that) and costs nothing in production builds, where devtools reporting is removed.