@beignet/react-query 0.0.21 → 0.0.23
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/CHANGELOG.md +8 -0
- package/README.md +48 -0
- package/package.json +1 -1
- package/skills/client/SKILL.md +11 -4
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -68,6 +68,54 @@ export function Providers({ children }: { children: ReactNode }) {
|
|
|
68
68
|
}
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
### 3. Add feature client helpers
|
|
72
|
+
|
|
73
|
+
Keep root `client/` for shared adapter setup, then put feature-specific query
|
|
74
|
+
options, mutation options, invalidation helpers, and hooks under
|
|
75
|
+
`features/<feature>/client/`:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
// features/todos/client/queries.ts
|
|
79
|
+
import type { QueryClient } from "@tanstack/react-query";
|
|
80
|
+
import { rq } from "@/client";
|
|
81
|
+
import { createTodo, listTodos } from "@/features/todos/contracts";
|
|
82
|
+
|
|
83
|
+
export function listTodosQueryOptions() {
|
|
84
|
+
return rq(listTodos).queryOptions({ query: {} });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function createTodoMutationOptions() {
|
|
88
|
+
return rq(createTodo).mutationOptions();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function invalidateTodos(queryClient: QueryClient) {
|
|
92
|
+
return rq(listTodos).invalidate(queryClient);
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Components can import those helpers and keep UI state separate from cache-key
|
|
97
|
+
construction:
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
101
|
+
import {
|
|
102
|
+
createTodoMutationOptions,
|
|
103
|
+
invalidateTodos,
|
|
104
|
+
listTodosQueryOptions,
|
|
105
|
+
} from "@/features/todos/client/queries";
|
|
106
|
+
|
|
107
|
+
function TodoList() {
|
|
108
|
+
const queryClient = useQueryClient();
|
|
109
|
+
const todosQuery = useQuery(listTodosQueryOptions());
|
|
110
|
+
const createTodoMutation = useMutation({
|
|
111
|
+
...createTodoMutationOptions(),
|
|
112
|
+
onSuccess: () => invalidateTodos(queryClient),
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
return <div>{/* ... */}</div>;
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
71
119
|
## Usage
|
|
72
120
|
|
|
73
121
|
### Options-first API (recommended)
|
package/package.json
CHANGED
package/skills/client/SKILL.md
CHANGED
|
@@ -53,14 +53,21 @@ Follow the existing style unless intentionally migrating. Do not mix both
|
|
|
53
53
|
within one feature.
|
|
54
54
|
|
|
55
55
|
```ts
|
|
56
|
+
import type { QueryClient } from "@tanstack/react-query";
|
|
56
57
|
import { rq } from "@/client";
|
|
57
58
|
import { createTodo, listTodos } from "@/features/todos/contracts";
|
|
58
59
|
|
|
59
|
-
export
|
|
60
|
-
rq(listTodos).queryOptions({ query: { limit: 20 } });
|
|
60
|
+
export function listTodosQueryOptions() {
|
|
61
|
+
return rq(listTodos).queryOptions({ query: { limit: 20 } });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function createTodoMutationOptions() {
|
|
65
|
+
return rq(createTodo).mutationOptions();
|
|
66
|
+
}
|
|
61
67
|
|
|
62
|
-
export
|
|
63
|
-
rq(
|
|
68
|
+
export function invalidateTodos(queryClient: QueryClient) {
|
|
69
|
+
return rq(listTodos).invalidate(queryClient);
|
|
70
|
+
}
|
|
64
71
|
```
|
|
65
72
|
|
|
66
73
|
## Components
|