Interface: UseAsyncReturn<T, A, E>
Defined in: use-async.ts:45
The return value of useAsync.
Type Parameters
T
T
The type of data the async function resolves with.
A
A extends unknown[]
The argument list of the async function.
E
E = unknown
The type of error the async function rejects with.
Properties
data
data:
T|undefined
Defined in: use-async.ts:49
The latest successful result. It is kept while a new run is pending or after one fails.
error
error:
E|undefined
Defined in: use-async.ts:51
The error of the latest run, or undefined while it is pending or after it succeeds.
isPending
isPending:
boolean
Defined in: use-async.ts:53
Shorthand for status === "pending".
reset
reset: () =>
void
Defined in: use-async.ts:61
Go back to idle with initialData, and ignore any run still in flight.
Returns
void
run
run: (...
args) =>Promise<AsyncResult<T,E>>
Defined in: use-async.ts:59
Run the async function with the given arguments. Resolves with the outcome instead of rejecting. If a newer run starts first, this one still resolves with its own outcome but no longer updates the state.
Parameters
args
...A
Returns
Promise<AsyncResult<T, E>>
status
status:
AsyncStatus
Defined in: use-async.ts:47
The lifecycle phase: idle until the first run, then pending, success or error.