# useWrite

> For the complete documentation index, see [llms.txt](https://ensforge.com/llms.txt).

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

Source: https://ensforge.com/docs/reference/react/use-write

<ApiMeta kind="Write hook" stability="stable" since="1.0.0" source="packages/react/src/hooks/useWrite.ts#L86" />

Sends any ensforge write and tracks it.

## When to use [#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 [#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 [#signature]

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

## Examples [#examples]

```tsx title="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 [#see-also]

- The [hook types](/docs/reference/react#types): `ReadResult`, `WriteResult` and `ReadConfig`.