UNPKG

725 BTypeScriptView Raw
1/**
2 * @name useRequest
3 * @author Fajar Rizky Hidayat <fajarrizkyhidayat@gmail.com>
4 */
5
6
7
8interface RequestProps<T = any> {
9 data: T;
10}
11type ExecProps<T = any> = {
12 service: (event?: import('.').EventSend<T>) => Promise<any>;
13 onSuccess?: (<P = T>(data: any) => P) | ((data: any) => void);
14 onError?: (e: any) => void;
15 onAlways?: () => void;
16};
17
18type UseRequest<T = any> = {
19 isEmpty: boolean;
20 loading: boolean;
21 data: T;
22 exec: (options: ExecProps<T>) => void;
23 query: (key?: string, defaultValue?: any) => any;
24 setQuery: (value: any | ((obj: any) => any)) => void;
25 clear: (clean?: boolean) => void;
26 cancel: () => void;
27};
28
29export default function useRequest<T>(props: RequestProps<T>): UseRequest<T>;