State properties | React Async
State properties
These are returned in an object by useAsync() or provided by <Async> as render props to the children function:
dataLast resolved promise value, maintained when new error arrives.errorRejected promise reason, cleared when new data arrives.valueThe value ofdataorerror, whichever was last updated.initialValueThe data or error that was provided through theinitialValueprop.startedAtWhen the current/last promise was started.finishedAtWhen the last promise was fulfilled or rejected.statusOne of:initial,pending,fulfilled,rejected.isInitialtrue when no promise has ever started, or one started but was cancelled.isPendingtrue when a promise is currently awaiting settlement. Alias:isLoadingisFulfilledtrue when the last promise was fulfilled. Alias:isResolvedisRejectedtrue when the last promise was rejected.isSettledtrue when the last promise was fulfilled or rejected (not initial or pending).counterThe number of times a promise was started.promiseA reference to the internal wrapper promise, which can be chained on.reloadRe-runs the promise when invoked, using any previous arguments.cancelCancel any pending promise.setDataSetsdatato the passed value, unsetserrorand cancels any pending promise.setErrorSetserrorto the passed value and cancels any pending promise.
any
Last resolved promise value, maintained when new error arrives.
Error
Rejected promise reason, cleared when new data arrives.
any | Error
The data or error that was last provided (either through initialValue or by settling a promise).
any | Error
The data or error that was originally provided through the initialValue prop.
Date
Tracks when the current/last promise was started.
Date
Tracks when the last promise was resolved or rejected.
string
One of: initial, pending, fulfilled, rejected. These are available for import as statusTypes.
boolean
true while no promise has started yet, or one was started but cancelled.
boolean
true while a promise is pending (loading), false otherwise.
Alias: isLoading
boolean
true when the last promise was fulfilled (resolved to a value).
Alias: isResolved
boolean
true when the last promise was rejected.
boolean
true when the last promise was either fulfilled or rejected (i.e. not initial or pending)
number
The number of times a promise was started.
Promise
A reference to the internal wrapper promise created when starting a new promise (either automatically or by invoking run / reload). It fulfills or rejects along with the provided promise / promiseFn / deferFn. Useful as a chainable alternative to the onResolve / onReject callbacks.
Warning! If you chain on promise, you MUST provide a rejection handler (e.g. .catch(...)). Otherwise React will throw an exception and crash if the promise rejects.
function(...args: any[]): void
Runs the deferFn, passing any arguments provided as an array.
When used with useFetch, run has several overloaded signatures:
function(override: OverrideParams | (params: OverrideParams) => OverrideParams): void
function(event: SyntheticEvent | Event): void
function(): void
Where type OverrideParams = { resource?: RequestInfo } & Partial<RequestInit>.
This way you can run the fetch request with custom resource and init. If override is an object it will be spread over the default resource and init for fetch. If it's a function it will be invoked with the params defined with useFetch, and should return an override object. This way you can either extend or override the value of resource and init, for example to change the URL or set custom request headers.
function(): void
Re-runs the promise when invoked, using the previous arguments.
function(): void
Cancels the currently pending promise by ignoring its result and calls abort() on the AbortController.
function(data: any, callback?: () => void): any
Function that sets data to the passed value, unsets error and cancels any pending promise. Takes an optional callback which is invoked after the state update is completed. Returns the data to enable chaining.
function(error: Error, callback?: () => void): Error
Function that sets error to the passed value and cancels any pending promise. Takes an optional callback which is invoked after the state update is completed. Returns the error to enable chaining.