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
undefinedoptions (orenabled: 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
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,WriteResultandReadConfig.
Was this page helpful?