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
mutateAsyncsettles with its own write. stepslists 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
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,WriteResultandReadConfig.
Was this page helpful?