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

useRead

Reads with any ensforge action and keeps the result fresh. Signature, options, result and examples for useRead in @ensforge/react.

Read hookstable
Since v1.0.0View source

Reads with any ensforge action and keeps the result fresh.

When to use

Use for any read, from either @ensforge/sdk or @ensforge/sdk/effect. Named hooks such as useAddress are presets of this one.

Details

  • Components reading the same action and options share one request and one cached result.
  • Unmounting keeps the result, and a request in flight, cached for idleTTL; a remount within it reuses them, and retries a failed read. Writes that touch the read's names or accounts refetch it.
  • Pass undefined options (or enabled: false) to wait, e.g. until a name is typed.

Signature

function useRead<action extends Action>(action: action, options: ActionOptions<action> | undefined, config: ReadConfig = {}): ReadResult<ActionValue<action>, ActionError<action>>

Examples

Reading a role
import { Actions } from "@ensforge/sdk"
import { useRead } from "@ensforge/react"

function CanEdit({ name, account }: { name: string; account: `0x${string}` }) {
  const { data, isLoading } = useRead(Actions.permission.get, { name, account })
  return isLoading ? null : <span>{String(data?.can.setRecords)}</span>
}

See also

  • The hook types: ReadResult, WriteResult and ReadConfig.

Was this page helpful?