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, orReadErrorResetBoundary) 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
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,WriteResultandReadConfig.
Was this page helpful?