ActionResult
Reactive state and controls for an async action managed by useAction (and plugin-specific hooks built on top of it).
Lifecycle: starts at idle. Each dispatch(...) flips to running, then to success or
error depending on the outcome. data from a prior success and error from a prior failure
both persist through subsequent running states for stale-while-revalidate UX. success clears
error; only reset() clears data.
Calling dispatch(...) while a previous call is in flight aborts the first via its
AbortSignal and replaces it. Fire-and-forget dispatch callers never observe this; awaiters of
a superseded dispatchAsync call see a rejection with an AbortError, filterable via
isAbortError from @solana/promises.
Type Parameters
| Type Parameter | Description |
|---|---|
TArgs extends readonly unknown[] | The argument tuple dispatch accepts; forwarded to the wrapped function after the abort signal. |
TResult | The value the wrapped function resolves to on success. |
Properties
data
The result on success, or undefined if no successful call has happened yet.
dispatch
Trigger the action and forget it. Returns undefined synchronously and never throws —
failures surface on status / error, and superseded or reset()-aborted calls produce no
state change. This is the variant to wire into UI event handlers (onClick={() => dispatch()}):
there is no promise to handle, so it can't produce an unhandled rejection. Calling dispatch
again while a prior call is in flight aborts the first. Stable reference.
Parameters
| Parameter | Type |
|---|---|
...args | TArgs |
Returns
void
See
ActionResult.dispatchAsync when you need the resolved value or propagated errors.
dispatchAsync
Trigger the action and await the outcome. Resolves with the wrapped function's result, or
rejects with the thrown error. Calling dispatch/dispatchAsync again while a prior call is
in flight aborts the first and rejects its promise with an AbortError. Stable reference.
Mirrors ReactiveActionStore.dispatchAsync. Use this from imperative callers that read the
resolved value (e.g. to navigate on success); filter supersede rejections with isAbortError
from @solana/promises. Prefer ActionResult.dispatch from event handlers that don't
await — its returned promise, left unhandled, surfaces every supersede/abort as an
unhandledrejection.
Parameters
| Parameter | Type |
|---|---|
...args | TArgs |
Returns
Promise<TResult>
error
The error from the most recent failed call, or undefined. Persists through a subsequent
running state so UIs can keep showing the prior failure while a retry is in flight; a
subsequent success clears it.
isError
true when status === 'error'.
isIdle
true when status === 'idle'.
isRunning
true when status === 'running' — a dispatch is in flight.
isSuccess
true when status === 'success'.
reset
Reset state back to idle, aborting any in-flight call. Stable reference.
Returns
void
status
The current lifecycle status as a discriminated string. The isIdle / isRunning /
isSuccess / isError booleans below are derived from this — pick whichever reads better
at the call site.