@umang-thakkar/base-template 1.0.1 → 1.0.3
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/README.md +4 -1
- package/package.json +1 -1
- package/template/src/api/queries.ts +31 -15
package/README.md
CHANGED
|
@@ -74,7 +74,10 @@ template/
|
|
|
74
74
|
|
|
75
75
|
## 🚀 Getting Started
|
|
76
76
|
|
|
77
|
-
1.
|
|
77
|
+
1. Create a new project using this template:
|
|
78
|
+
```sh
|
|
79
|
+
npx @react-native-community/cli init MyApp --template @umang-thakkar/base-template
|
|
80
|
+
Note: Replace MyApp with your own project name.
|
|
78
81
|
2. Install dependencies:
|
|
79
82
|
```sh
|
|
80
83
|
npm install
|
package/package.json
CHANGED
|
@@ -1,22 +1,38 @@
|
|
|
1
1
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
2
2
|
import { addTodo, deleteTodo, fetchTodoById, fetchTodos } from "./service";
|
|
3
|
-
const queryClient = useQueryClient()
|
|
4
3
|
|
|
5
|
-
export const useTodos = useQuery({ queryKey: ['todos'], queryFn: fetchTodos });
|
|
6
4
|
|
|
7
|
-
export const
|
|
5
|
+
export const useTodos = () => {
|
|
6
|
+
return useQuery({
|
|
7
|
+
queryKey: ['todos'],
|
|
8
|
+
queryFn: fetchTodos
|
|
9
|
+
});
|
|
10
|
+
};
|
|
8
11
|
|
|
9
|
-
export const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
}
|
|
12
|
+
export const useTodoById = (id: number) => {
|
|
13
|
+
return useQuery({
|
|
14
|
+
queryKey: ['todo', id],
|
|
15
|
+
queryFn: () => fetchTodoById(id)
|
|
16
|
+
});
|
|
17
|
+
};
|
|
15
18
|
|
|
16
|
-
export const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
19
|
+
export const useAddTodo = () => {
|
|
20
|
+
const queryClient = useQueryClient()
|
|
21
|
+
return useMutation({
|
|
22
|
+
mutationFn: addTodo,
|
|
23
|
+
onSuccess: () => {
|
|
24
|
+
queryClient.invalidateQueries({ queryKey: ['todos'] });
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const useDeleteTodo = () => {
|
|
30
|
+
const queryClient = useQueryClient()
|
|
31
|
+
return useMutation({
|
|
32
|
+
mutationFn: deleteTodo,
|
|
33
|
+
onSuccess: () => {
|
|
34
|
+
queryClient.invalidateQueries({ queryKey: ['todos'] });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
};
|
|
22
38
|
|