1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | interface FetchProps<T = any> {
|
7 | service: (resp?: import(".").EventSend<T>) => any;
|
8 | selector: (resp: any) => any;
|
9 | defaultValue?: T;
|
10 | disabledOnDidMount?: boolean;
|
11 | debounceTime?: number;
|
12 | cache?: {
|
13 | key?: string;
|
14 | |
15 |
|
16 |
|
17 |
|
18 | ttl?: number;
|
19 | |
20 |
|
21 |
|
22 |
|
23 | periodTime?: number;
|
24 | periodically?: boolean;
|
25 | };
|
26 | deps?: any[];
|
27 | getData?: (value: any) => void;
|
28 | }
|
29 |
|
30 | type UseFetch<T = any> = {
|
31 | isEmpty: boolean;
|
32 | loading: boolean;
|
33 | data: T;
|
34 | query: object;
|
35 | setQuery: (value: any | ((obj: any) => any)) => void;
|
36 | clear: (fields?: {
|
37 | except?: ReadonlyArray<keyof T>;
|
38 | only?: ReadonlyArray<keyof T>;
|
39 | }) => void;
|
40 | refresh: () => void;
|
41 | add: (newValue: T, position?: "start" | "end" | number) => void;
|
42 | update: (condition: (data: T) => boolean, newValue: Partial<T>) => void;
|
43 | destroy: (condition: (data: T) => boolean) => void;
|
44 | getQuery: (key: string, defaultValue?: any) => any;
|
45 | has: (key: string) => boolean;
|
46 | cancel: () => void;
|
47 | };
|
48 |
|
49 | export default function useFetch<T>(props: FetchProps<T>): UseFetch<T>;
|