useAsync()
useAsync( CALLABLE asyncFunction[, BOOLEAN immediate = true ] )
We got this one from useHooks, so check that out for extra details.
Parameters
asyncFunction(CALLABLE, Required, default: none) Pretty sure a syncronous function will cause an error.immediate(BOOLEAN, Optional, default: true) If this is true, the hook will execute asyncFunction() immediately and fill status, value, and (hopefully not) error.
Returns
(OBJECT) { execute, status, value, error }
execute(CALLABLE) Call this to execute yourasyncFunction.status(STRING) Is"idle"when nothing is happening. Is"pending"when the function in progress. Is"success"afterexecute()executes without error. Is"error"when the function throws an error.value(MIXED)error(STRING)
Examples
import { useAsync } from "@preemptivelove/utilities-js"const returnsPromise = ()=> new Promiseconst { execute, status, value, error } = useAsync( returnsPromise )
Something more useful here later.
Source
https://github.com/PreemptiveLove/utilities-js/blob/master/src/hooks/useAsync.js