@umang-thakkar/base-template 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/template/src/api/queries.ts +28 -14
package/package.json
CHANGED
|
@@ -2,21 +2,35 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
|
2
2
|
import { addTodo, deleteTodo, fetchTodoById, fetchTodos } from "./service";
|
|
3
3
|
const queryClient = useQueryClient()
|
|
4
4
|
|
|
5
|
-
export const useTodos =
|
|
5
|
+
export const useTodos = () => {
|
|
6
|
+
return useQuery({
|
|
7
|
+
queryKey: ['todos'],
|
|
8
|
+
queryFn: fetchTodos
|
|
9
|
+
});
|
|
10
|
+
};
|
|
6
11
|
|
|
7
|
-
export const useTodoById = (id: number) =>
|
|
12
|
+
export const useTodoById = (id: number) => {
|
|
13
|
+
return useQuery({
|
|
14
|
+
queryKey: ['todo', id],
|
|
15
|
+
queryFn: () => fetchTodoById(id)
|
|
16
|
+
});
|
|
17
|
+
};
|
|
8
18
|
|
|
9
|
-
export const useAddTodo =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
19
|
+
export const useAddTodo = () => {
|
|
20
|
+
return useMutation({
|
|
21
|
+
mutationFn: addTodo,
|
|
22
|
+
onSuccess: () => {
|
|
23
|
+
queryClient.invalidateQueries({ queryKey: ['todos'] });
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
};
|
|
15
27
|
|
|
16
|
-
export const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
28
|
+
export const useDeleteTodo = () => {
|
|
29
|
+
return useMutation({
|
|
30
|
+
mutationFn: deleteTodo,
|
|
31
|
+
onSuccess: () => {
|
|
32
|
+
queryClient.invalidateQueries({ queryKey: ['todos'] });
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
22
36
|
|