1
1
{{> header }}
2
+ import { useQuery, useMutation } from '@tanstack/react-query';
3
+ import type { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
2
4
3
- import { useQuery, useMutation } from '@anyroad/hooks';
4
- import type { UseQueryOptions, UseMutationOptions } from '@anyroad/hooks';
5
5
import { {{ clientName }} } from '../../client';
6
6
{{ #if imports }}
7
7
{{ #each imports }}
@@ -14,23 +14,34 @@ const client = new {{clientName}}();
14
14
{{ #each operations }}
15
15
{{ #equals method ' GET' }}
16
16
export const use{{ pascalCase name }} = ({{ #if parameters }} {{> parameters }} {{ else }} _: any{{ /if }} , options?: UseQueryOptions<{{ >result}}>) => {
17
- return useQuery<{{ >result}}>(['{{ camelCase service }} ', '{{ camelCase name }} ', {{ #each parameters }} {{ name }} , {{ /each }} ], async () => {
18
- return client.{{ camelCase service }} .{{ name }} ({{ #if parameters }} {
19
- {{ #each parameters }}
20
- {{ name }} ,
21
- {{ /each }}
22
- }{{ /if }} );
23
- }, options);
17
+ return useQuery<{{ >result}}>({
18
+ queryKey: ['{{ camelCase service }} ', '{{ camelCase name }} ', {{ #each parameters }} {{ name }} , {{ /each }} ],
19
+ queryFn: async () => {
20
+ return client.{{ camelCase service }} .{{ name }} ({{ #if parameters }} {
21
+ {{ #each parameters }}
22
+ {{ #if name }}
23
+ {{ name }} ,
24
+ {{ else }}
25
+ _,
26
+ {{ /if }}
27
+ {{ /each }}
28
+ }{{ /if }} );
29
+ },
30
+ ...options
31
+ });
24
32
};
25
33
{{ else }}
26
34
export const use{{ pascalCase name }} = (options?: UseMutationOptions<{{ >result}}>) => {
27
- return useMutation<{{ >result}}, any, any>(async ({{> parameters }} ) => {
28
- return client.{{ camelCase service }} .{{ name }} ({{ #if parameters }} {
29
- {{ #each parameters }}
30
- {{ name }} ,
31
- {{ /each }}
32
- }{{ /if }} );
33
- }, options);
35
+ return useMutation<{{ >result}}, any, any>({
36
+ mutationFn: async ({{> parameters }} ) => {
37
+ return client.{{ camelCase service }} .{{ name }} ({{ #if parameters }} {
38
+ {{ #each parameters }}
39
+ {{ name }} ,
40
+ {{ /each }}
41
+ }{{ /if }} );
42
+ },
43
+ ...options
44
+ });
34
45
};
35
46
{{ /equals }}
36
47
{{ /each }}
0 commit comments