@ohm-vision/react-async
Version:
Extentions to React to support asynchronous calls
17 lines (16 loc) • 607 B
JavaScript
import { useAsync } from "./useAsync";
/**
* Wraps and creates a memo-like result using the `useState`
*
* `useMemoAsync` 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`
*/
export function useMemoAsync(factory, deps, destructor) {
var result = useAsync(factory, deps, destructor)[0];
return result;
}