import type { AnyFunc, Gettable, Promisable } from "../utils/basic.js"; export interface UseAsyncFnOptions>, E = any> { /** * Initial data to be used as the initial value * * @defaultValue undefined * * @since 1.4.0 */ initialValue?: D; /** * Initial parameters passed to fetcher when first mount * * @defaultValue [] * * @since 1.4.0 */ initialParams?: Gettable | []>>; /** * whether to run the async function immediately on component mount * * @defaultValue false * * @since 1.4.0 */ immediate?: boolean; /** * whether to clear the value before running the function * * @defaultValue false */ clearBeforeRun?: boolean; /** * whether to cancel the async function when the component is unmounted * * @defaultValue true * * @since 1.4.0 */ cancelOnUnmount?: boolean; /** * a function to run when the async function throws an error * * @defaultValue undefined * * @since 1.4.0 */ onError?: (error: E | undefined, params: Parameters | []) => void; /** * a function to run before the async function * * @defaultValue undefined * * @since 1.4.0 */ onBefore?: (value: D | undefined, params: Parameters | []) => void; /** * a function to run after the async function * * @defaultValue undefined * * @since 1.4.0 */ onSuccess?: (value: D, params: Parameters | []) => void; /** * a function to run after the async function * * @defaultValue undefined * * @since 1.4.0 */ onFinally?: (value: D | undefined, params: Parameters | []) => void; /** * a function to run when the async function is cancelled * * @defaultValue undefined * * @since 1.4.0 */ onCancel?: (value: D | undefined, params: Parameters | []) => void; /** * a function to run when the value is mutated * * @defaultValue undefined * * @since 1.4.0 */ onMutate?: (value: D | undefined, params: Parameters | []) => void; /** * a function to run when the value is refreshed * * @defaultValue undefined * * @since 1.4.0 */ onRefresh?: (value: D | undefined, params: Parameters | []) => void; /** * Custom cache comparison function, `true` means the cache is the same * * @defaultValue shallowEqual * * @since 1.4.0 */ compare?: (prevData: D | undefined, nextData: D | undefined) => boolean; } export type UseAsyncFnMutateAction = [D | undefined] | [D | undefined, P | undefined] | [(prevData: D | undefined, preParams?: P) => [D, P | undefined]]; export interface UseAsyncFnReturns>, E = any> { /** * a function to run the async function */ run: T; /** * a function to refresh the async function */ refresh: (params?: Parameters | []) => Promise; /** * a function to cancel the async function */ cancel: () => void; /** * manually set the value */ mutate: (...actions: UseAsyncFnMutateAction | []>) => void; /** * whether the async function is loading */ loading: boolean; /** * the error thrown by the async function */ error: E | undefined; /** * the value returned by the async function */ value: D | undefined; /** * the parameters passed to the async function */ params: Parameters | []; } export declare function resolveMutateActions(actions: UseAsyncFnMutateAction, prevData: D, prevParams: P): [D, P]; /** * A React Hook to run **async** functions with extra **loading** state that indicates whether the promise is pending. * * @param {AnyFunc} fn - `AnyFunc`, the async function to run, see {@link AnyFunc} * @returns {UseAsyncFnReturns} `UseAsyncFnReturns`, see {@link UseAsyncFnReturns} */ export declare function useAsyncFn>, E = any>(fn: T, options?: UseAsyncFnOptions): UseAsyncFnReturns;