@react-hookz/web
Version:
React hooks done right, for browser and SSR.
29 lines (28 loc) • 1.39 kB
TypeScript
import { IAsyncState, IUseAsyncActions, IUseAsyncMeta } from '..';
export interface IUseAsyncAbortableActions<Result, Args extends unknown[] = unknown[]> extends IUseAsyncActions<Result, Args> {
/**
* Abort currently running async.
*/
abort: () => void;
/**
* Abort currently running async and reset state to initial, when async function haven't been executed.
*/
reset: () => void;
}
export interface IUseAsyncAbortableMeta<Result, Args extends unknown[] = unknown[]> extends IUseAsyncMeta<Result, Args> {
/**
* Current abort controller. New one created each async execution.
*/
abortController: AbortController | undefined;
}
export declare type IArgsWithAbortSignal<Args extends unknown[] = unknown[]> = [AbortSignal, ...Args];
export declare function useAsyncAbortable<Result, Args extends unknown[] = unknown[]>(asyncFn: (...params: IArgsWithAbortSignal<Args>) => Promise<Result>, initialValue: Result): [
IAsyncState<Result>,
IUseAsyncAbortableActions<Result, Args>,
IUseAsyncAbortableMeta<Result, Args>
];
export declare function useAsyncAbortable<Result, Args extends unknown[] = unknown[]>(asyncFn: (...params: IArgsWithAbortSignal<Args>) => Promise<Result>, initialValue?: Result): [
IAsyncState<Result | undefined>,
IUseAsyncAbortableActions<Result, Args>,
IUseAsyncAbortableMeta<Result, Args>
];