useAction
Bridge an arbitrary async function into a reactive ActionResult. Each send(...) call
runs the function with a fresh AbortSignal and tracks its lifecycle through React state;
a second call while a first is in flight aborts the first.
fn is held in a ref that always points at the latest closure — there is no deps array to
maintain. Each send(...) invokes the most recently rendered fn, so values captured inside
(e.g. form state, route params) are always fresh without explicit dependency tracking. This
matches the convention used by useMutation in TanStack Query and useWriteContract in wagmi.
In-flight calls are unaffected — they continue with the closure they captured at dispatch time.
Type Parameters
| Type Parameter | Description |
|---|---|
TArgs extends readonly unknown[] | The argument tuple send accepts; forwarded to fn after the abort signal. |
TResult | The value fn resolves to on success. |
Parameters
| Parameter | Type |
|---|---|
fn | (signal, ...args) => Promise<TResult> |
Returns
ActionResult<TArgs, TResult>