useAsync()
or provided by <Async>
as render props to the children
function:data
any
error
Error
value
any | Error
initialValue
or by settling a promise).initialValue
any | Error
initialValue
prop.startedAt
Date
finishedAt
Date
status
string
initial
, pending
, fulfilled
, rejected
. These are available for import as statusTypes
.isInitial
boolean
true
while no promise has started yet, or one was started but cancelled.isPending
boolean
true
while a promise is pending (loading), false
otherwise.isLoading
isFulfilled
boolean
true
when the last promise was fulfilled (resolved to a value).isResolved
isRejected
boolean
true
when the last promise was rejected.isSettled
boolean
true
when the last promise was either fulfilled or rejected (i.e. not initial or pending)counter
number
promise
Promise
run
/ reload
). It fulfills or rejects along with the provided promise
/ promiseFn
/ deferFn
. Useful as a chainable alternative to the onResolve
/ onReject
callbacks.promise
, you MUST provide a rejection handler (e.g. .catch(...)
). Otherwise React will throw an exception and crash if the promise rejects.run
function(...args: any[]): void
deferFn
, passing any arguments provided as an array.useFetch
, run
has several overloaded signatures:function(override: OverrideParams | (params: OverrideParams) => OverrideParams): void
function(event: SyntheticEvent | Event): void
function(): void
type OverrideParams = { resource?: RequestInfo } & Partial<RequestInit>
.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.reload
function(): void
cancel
function(): void
abort()
on the AbortController.setData
function(data: any, callback?: () => void): any
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.setError
function(error: Error, callback?: () => void): Error
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.