@sanity/form-builder
Version:
Sanity form builder
22 lines • 1.01 kB
TypeScript
import React from 'react';
export declare type AsyncCompleteState<T> = {
status: 'complete';
result: T;
};
export declare type AsyncPendingState = {
status: 'pending';
};
export declare type AsyncErrorState = {
status: 'error';
error: Error;
};
export declare type AsyncState<T> = AsyncPendingState | AsyncCompleteState<T> | AsyncErrorState;
/**
* Takes an async function and returns a [AsyncState<value>, callback] pair.
* Whenever the callback is invoked, a new AsyncState is returned.
* If the returned callback is called again before the previous callback has settled, the resolution of the previous one will be ignored, thus preventing race conditions.
* @param fn an async function that returns a value
* @param dependencies list of dependencies that will return a new [value, callback] pair
*/
export declare function useAsync<T, U>(fn: (arg: U) => Promise<T>, dependencies: React.DependencyList): [null | AsyncState<T>, (arg: U) => void];
//# sourceMappingURL=useAsync.d.ts.map