1 | import type { CacheAxiosResponse } from 'axios-cache-interceptor';
|
2 | /** The internal axios state used by `axios-cache-hooks` */
|
3 | export declare type State<T> = LoadingState | ErrorState | SuccessState<T>;
|
4 | export declare type LoadingState = {
|
5 | /** If the current request is loading */
|
6 | loading: true;
|
7 | /** The returned data for this request, if present */
|
8 | data?: undefined;
|
9 | /** The error thrown by this http request, if any */
|
10 | error?: undefined;
|
11 | /** The complete `CacheAxiosResponse` */
|
12 | response?: undefined;
|
13 | };
|
14 | export declare type ErrorState = {
|
15 | /** If the current request is loading */
|
16 | loading: false;
|
17 | /** The returned data for this request, if present */
|
18 | data?: undefined;
|
19 | /** The error thrown by this http request, if any */
|
20 | error: unknown;
|
21 | /** The complete `CacheAxiosResponse` */
|
22 | response?: CacheAxiosResponse;
|
23 | };
|
24 | export declare type SuccessState<D> = {
|
25 | /** If the request is loading */
|
26 | loading: false;
|
27 | /** The returned data for this request, if present */
|
28 | data: D;
|
29 | /** The error thrown by this http request, if any */
|
30 | error?: undefined;
|
31 | /** The complete `CacheAxiosResponse` */
|
32 | response: CacheAxiosResponse<D>;
|
33 | };
|
34 | /**
|
35 | * This is where you should define your custom axios request logic.
|
36 | *
|
37 | * **Note**: Remember to ALWAYS spread the {@link AxiosRequestConfig} object in the axios call.
|
38 | */
|
39 | export declare type ApiCall<D, A extends unknown[]> = (...args: A) => Promise<CacheAxiosResponse<D>>;
|
40 | /**
|
41 | * The current request state.
|
42 | *
|
43 | * The response data was provided as the in the first object of this tuple.
|
44 | */
|
45 | export declare type DataLessState<D> = Omit<State<D>, 'data'>;
|
46 | export declare type AxiosCacheHooks = {
|
47 | /**
|
48 | * Uses the provided `apiCall` to execute a axios request.
|
49 | *
|
50 | * Make sure the `apiCall` function has an `CacheRequestConfig` argument in the same
|
51 | * index as your `configIndexFinder` defined.
|
52 | *
|
53 | * **Note**: This is different from `useMutation` because it calls the axios request
|
54 | * directly on the first render.
|
55 | *
|
56 | * @example
|
57 | *
|
58 | * ```tsx
|
59 | * const [user, { loading }] = useQuery(getUser, 'Arthur');
|
60 | *
|
61 | * if (loading) {
|
62 | * return <div>Loading...</div>;
|
63 | * }
|
64 | *
|
65 | * return <div>{user.name}</div>;
|
66 | * ```
|
67 | *
|
68 | * @param apiCall The function that will return a {@link CacheAxiosResponse}
|
69 | * @param args Arguments to pass to the `apiCall`. You can change this arguments without
|
70 | * any problems.
|
71 | * @see http://tinylibs.js.org/packages/axios-cache-hooks
|
72 | */
|
73 | useQuery<D, A extends unknown[]>(this: void, apiCall: ApiCall<D, A>, ...args: A): [data: D | undefined, info: DataLessState<D>];
|
74 | /**
|
75 | * Uses the provided `apiCall` to execute a axios request when the returned `refetch`
|
76 | * function is called.
|
77 | *
|
78 | * Make sure the `apiCall` function has an `CacheRequestConfig` argument in the same
|
79 | * index as your `configIndexFinder` defined.
|
80 | *
|
81 | * **Note**: This is different from `useQuery` because it **DOES NOT** calls the axios
|
82 | * request on the first render.
|
83 | *
|
84 | * @example
|
85 | *
|
86 | * ```tsx
|
87 | * const [state, refetch] = useMutation(createUser);
|
88 | *
|
89 | * return <button onClick={() => refetch('Arthur')}>Create profile!</button>;
|
90 | * ```
|
91 | *
|
92 | * @param apiCall The function that will return a {@link CacheAxiosResponse}.
|
93 | * @see http://tinylibs.js.org/packages/axios-cache-hooks
|
94 | */
|
95 | useMutation<D, A extends unknown[]>(this: void, apiCall: ApiCall<D, A>): [state: State<D>, refetch: (...args: A) => void];
|
96 | };
|
97 | //# sourceMappingURL=types.d.ts.map |
\ | No newline at end of file |