useAction
Bridge an arbitrary async function into a reactive ActionResult. Each dispatch(...)
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 dispatch(...) invokes the most recently rendered fn, so values captured
inside (e.g. form state, route params) are always fresh without explicit dependency tracking.
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 dispatch 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>