@ohm-vision/react-async
Version:
Extentions to React to support asynchronous calls
14 lines (13 loc) • 703 B
TypeScript
import { DependencyList, EffectCallback } from "react";
/**
* Wraps and creates a memo-like result using the `useState`
*
* `useAsync` will only recompute the memoized value when one of the `deps` has changed
*
* **Note**: Just like with the native `useMemo`, this will return the previous value until the calculation has changed
* @param factory Asynchronous function to call
* @param deps Dependency List
* @param destructor Destructor
* @returns [ `TResult | undefined` | `boolean` ]
*/
export declare function useAsync<TResult>(factory: (abortController: AbortController) => Promise<TResult>, deps: DependencyList, destructor?: ReturnType<EffectCallback>): [TResult | undefined, boolean];