Documentation for agents: an index at /llms.txt, every docs page in one file at /llms-full.txt, and Markdown for any docs page by adding .md to its URL.

Skip to Content
ensforgeReact

useSuspenseRead

Reads with an action and suspends until the value is there; failures throw to the nearest error boundary. Signature, result and examples for useSuspenseRead.

Read hookstable
Since v1.0.0View source

Reads with an action and suspends until the value is there; failures throw to the nearest error boundary.

When to use

Use inside <Suspense> boundaries, including server-rendered pages whose reads were prefetched.

Details

  • A failure is cached and thrown again until reset (useReadErrorReset, or ReadErrorResetBoundary) is called, which an error boundary's reset does; the read then runs again.
  • On the server, a read that was not prefetched throws, so React renders the boundary's fallback there and the read in the browser (React reports it as a recoverable error).

Signature

function useSuspenseRead<action extends Action>(action: action, options: ActionOptions<action>, config: Omit<ReadConfig, "enabled"> = {}): SuspenseReadResult<ActionValue<action>>

Examples

A profile behind Suspense
import { Actions } from "@ensforge/sdk"
import { useSuspenseRead } from "@ensforge/react"

function Url({ name }: { name: string }) {
  const { data } = useSuspenseRead(Actions.record.getText, { name, key: "url" })
  return <a href={data ?? "#"}>{data}</a>
}

See also

  • The hook types: ReadResult, WriteResult and ReadConfig.

Was this page helpful?