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

useWrite

Sends any ensforge write and tracks it. Signature, options, result and examples for useWrite in @ensforge/react. Signature, result and examples for useWrite.

Write hookstable
Since v1.0.0View source

Sends any ensforge write and tracks it.

When to use

Use for any write. Named hooks such as useSetRecords are presets of this one. Use the …Sync action (e.g. Actions.record.setSync) to resolve with receipts.

Details

  • Each component gets its own state; two buttons never share a result.
  • The state follows the latest write started; each mutateAsync settles with its own write.
  • steps lists plan events as they happen, for multi-step writes (approve, commit, register).
  • Afterwards, reads of the names and accounts it touched refetch: chain reads once mined, indexer reads once indexed.

Signature

function useWrite<action extends Action>(action: action, config: { readonly client?: Ensforge.Client | undefined } = {}): WriteResult<ActionOptions<action>, ActionValue<action>, ActionError<action>>

Examples

Saving records with progress
import { Actions } from "@ensforge/sdk"
import { useWrite } from "@ensforge/react"

function Save({ name }: { name: string }) {
  const { mutate, isPending, steps } = useWrite(Actions.record.set)
  return (
    <button disabled={isPending} onClick={() => mutate({ name, texts: { url: "https://alice.xyz" } })}>
      {isPending ? `${steps.length} step(s) done` : "Save"}
    </button>
  )
}

See also

  • The hook types: ReadResult, WriteResult and ReadConfig.

Was this page helpful?