react-redux-dispatch-async
Version:
hooks & redux middleware to be able to wait async actions with fixed defined suffixes
34 lines (33 loc) • 1.12 kB
TypeScript
import { Action } from 'redux';
import { DispatchAsyncResult } from './dispatchAsync';
interface ResultLoading {
status: 'loading';
}
interface ResultSuccess<R = unknown> {
status: 'success';
result: R;
}
interface ResultError {
status: 'error';
error: Error;
}
interface ResultCancel {
status: 'canceled';
}
interface ResultTimeout {
status: 'timeout';
}
interface ResultUnknown {
status: 'unknown';
}
declare type CompatActionResult<R> = (action: Action) => Promise<DispatchAsyncResult<R>>;
export declare type UseDispatchAsync<R = unknown> = ResultLoading | ResultSuccess<R> | ResultError | ResultTimeout | ResultCancel | ResultUnknown;
export declare type Status = Pick<UseDispatchAsync, 'status'>['status'];
export interface Options {
timeoutInMilliseconds?: number;
}
export declare function useCompatDispatchAsync<R = any>(action?: Action): CompatActionResult<R>;
export declare function useDispatchAsync<R = any>(actionFunction: (...args: any[]) => Action & {
payload: any;
}, deps?: any[], options?: Options): UseDispatchAsync<R>;
export {};