UNPKG

@yamada-ui/react

Version:

React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion

58 lines (57 loc) 1.92 kB
import { DependencyList } from "react"; //#region src/hooks/use-async/index.d.ts type FunctionReturningPromise = (...args: any[]) => Promise<any>; /** * `useAsync` is a custom hook that executes an asynchronous function and tracks its state. * * @see https://yamada-ui.com/docs/hooks/use-async */ declare function useAsync<Y$1 extends FunctionReturningPromise>(func: Y$1, deps?: DependencyList): StateFromFunctionReturningPromise<Y$1>; type AsyncState<Y$1> = { error: Error; loading: false; value?: undefined; } | { loading: boolean; error?: undefined; value?: undefined; } | { loading: false; value: Y$1; error?: undefined; } | { loading: true; error?: Error | undefined; value?: Y$1; }; type PromiseType<P extends Promise<any>> = P extends Promise<infer Y> ? Y : never; type StateFromFunctionReturningPromise<Y$1 extends FunctionReturningPromise> = AsyncState<PromiseType<ReturnType<Y$1>>>; type AsyncFnReturn<Y$1 extends FunctionReturningPromise = FunctionReturningPromise> = [StateFromFunctionReturningPromise<Y$1>, Y$1]; declare function useAsyncFunc<Y$1 extends FunctionReturningPromise>(func: Y$1, deps?: DependencyList, initialState?: StateFromFunctionReturningPromise<Y$1>): AsyncFnReturn<Y$1>; type AsyncStateRetry<Y$1> = AsyncState<Y$1> & { retry(): void; }; declare function useAsyncRetry<Y$1>(func: () => Promise<Y$1>, deps?: DependencyList): { retry: () => void; error: Error; loading: false; value?: undefined; } | { retry: () => void; loading: boolean; error?: undefined; value?: undefined; } | { retry: () => void; loading: false; value: Y$1; error?: undefined; } | { retry: () => void; loading: true; error?: Error | undefined; value?: Y$1 | undefined; }; //#endregion export { AsyncFnReturn, AsyncState, AsyncStateRetry, FunctionReturningPromise, PromiseType, useAsync, useAsyncFunc, useAsyncRetry }; //# sourceMappingURL=index.d.ts.map