react-query-kit 2.0.1 → 2.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/README.md CHANGED
@@ -384,20 +384,17 @@ import { Middleware, MutationHook, QueryHook, getKey } from 'react-query-kit'
384
384
  const myMiddleware: Middleware<
385
385
  QueryHook<Response, Variables>
386
386
  > = useQueryNext => {
387
- return (options, queryClient) => {
387
+ return options => {
388
388
  const { userId } = useAuth()
389
- const client = useQueryClient(queryClient)
389
+ const client = useQueryClient()
390
390
  const variables = options.variables ?? { id: userId }
391
391
  const hasData = () => !!client.getQueryData(useUser.getKey(variables))
392
392
 
393
- return useQueryNext(
394
- {
395
- ...options,
396
- variables,
397
- enabled: options.enabled ?? !hasData(),
398
- },
399
- queryClient
400
- )
393
+ return useQueryNext({
394
+ ...options,
395
+ variables,
396
+ enabled: options.enabled ?? !hasData(),
397
+ })
401
398
  }
402
399
  }
403
400
 
@@ -408,17 +405,17 @@ const useUser = createQuery<Response, Variables>({
408
405
 
409
406
  // global middlewares
410
407
  const queryMiddleware: Middleware<QueryHook> = useQueryNext => {
411
- return (options, queryClient) => {
408
+ return options => {
412
409
  // u can also get queryKey via function getKey
413
410
  const queryKey = getKey(options.primaryKey, options.variables)
414
411
  // ...
415
- return useQueryNext(options, queryClient)
412
+ return useQueryNext(options)
416
413
  }
417
414
  }
418
415
  const mutationMiddleware: Middleware<MutationHook> = useMutationNext => {
419
- return (options, queryClient) => {
416
+ return options => {
420
417
  // ...
421
- return useMutationNext(options, queryClient)
418
+ return useMutationNext(options)
422
419
  }
423
420
  }
424
421
 
@@ -480,6 +477,33 @@ enter a
480
477
  exit a
481
478
  ```
482
479
 
480
+ ### Multiple QueryClient
481
+
482
+ In ReactQuery v5, the `QueryClient` will be the second argument to `useQuery` and `useMutation`. If u have multiple `QueryClient` in global, u should receive `QueryClient` in middleware hook.
483
+
484
+ ```ts
485
+ const m1 = useQueryNext => {
486
+ return (options, queryClient) => {
487
+ const client = useQueryClient(queryClient)
488
+ // ...
489
+ return useQueryNext(options, queryClient)
490
+ }
491
+ }
492
+ const m2 = useQueryNext => {
493
+ return options => {
494
+ const client = useQueryClient()
495
+ // ...
496
+ return useQueryNext(options)
497
+ }
498
+ }
499
+ const useSomething = createQuery({ use: [m1, m2] })
500
+
501
+ function Example() {
502
+ // This will causes m2 to receive the wrong QueryClient.
503
+ useSomething({...}, anotherQueryClient)
504
+ }
505
+ ```
506
+
483
507
  ## Type inference
484
508
 
485
509
  You can extract the TypeScript type of any custom hook with `inferData` or `inferVariables`
@@ -4014,7 +4014,7 @@ var drawChart = (function (exports) {
4014
4014
  </script>
4015
4015
  <script>
4016
4016
  /*<!--*/
4017
- const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"name":"src","children":[{"uid":"a10d-1","name":"utils.ts"},{"uid":"a10d-3","name":"createBaseQuery.ts"},{"uid":"a10d-5","name":"createQuery.tsx"},{"uid":"a10d-7","name":"createSuspenseQuery.ts"},{"uid":"a10d-9","name":"createInfiniteQuery.ts"},{"uid":"a10d-11","name":"createSuspenseInfiniteQuery.ts"},{"uid":"a10d-13","name":"createMutation.ts"},{"uid":"a10d-15","name":"index.ts"}]}]}],"isRoot":true},"nodeParts":{"a10d-1":{"renderedLength":831,"gzipLength":395,"brotliLength":0,"mainUid":"a10d-0"},"a10d-3":{"renderedLength":999,"gzipLength":361,"brotliLength":0,"mainUid":"a10d-2"},"a10d-5":{"renderedLength":97,"gzipLength":90,"brotliLength":0,"mainUid":"a10d-4"},"a10d-7":{"renderedLength":271,"gzipLength":177,"brotliLength":0,"mainUid":"a10d-6"},"a10d-9":{"renderedLength":113,"gzipLength":99,"brotliLength":0,"mainUid":"a10d-8"},"a10d-11":{"renderedLength":287,"gzipLength":186,"brotliLength":0,"mainUid":"a10d-10"},"a10d-13":{"renderedLength":265,"gzipLength":173,"brotliLength":0,"mainUid":"a10d-12"},"a10d-15":{"renderedLength":0,"gzipLength":0,"brotliLength":0,"mainUid":"a10d-14"}},"nodeMetas":{"a10d-0":{"id":"/src/utils.ts","moduleParts":{"index.production.js":"a10d-1"},"imported":[{"uid":"a10d-16"}],"importedBy":[{"uid":"a10d-14"},{"uid":"a10d-12"},{"uid":"a10d-2"}]},"a10d-2":{"id":"/src/createBaseQuery.ts","moduleParts":{"index.production.js":"a10d-3"},"imported":[{"uid":"a10d-0"}],"importedBy":[{"uid":"a10d-4"},{"uid":"a10d-6"},{"uid":"a10d-8"},{"uid":"a10d-10"}]},"a10d-4":{"id":"/src/createQuery.tsx","moduleParts":{"index.production.js":"a10d-5"},"imported":[{"uid":"a10d-16"},{"uid":"a10d-2"}],"importedBy":[{"uid":"a10d-14"}]},"a10d-6":{"id":"/src/createSuspenseQuery.ts","moduleParts":{"index.production.js":"a10d-7"},"imported":[{"uid":"a10d-16"},{"uid":"a10d-2"}],"importedBy":[{"uid":"a10d-14"}]},"a10d-8":{"id":"/src/createInfiniteQuery.ts","moduleParts":{"index.production.js":"a10d-9"},"imported":[{"uid":"a10d-16"},{"uid":"a10d-2"}],"importedBy":[{"uid":"a10d-14"}]},"a10d-10":{"id":"/src/createSuspenseInfiniteQuery.ts","moduleParts":{"index.production.js":"a10d-11"},"imported":[{"uid":"a10d-16"},{"uid":"a10d-2"}],"importedBy":[{"uid":"a10d-14"}]},"a10d-12":{"id":"/src/createMutation.ts","moduleParts":{"index.production.js":"a10d-13"},"imported":[{"uid":"a10d-16"},{"uid":"a10d-0"}],"importedBy":[{"uid":"a10d-14"}]},"a10d-14":{"id":"/src/index.ts","moduleParts":{"index.production.js":"a10d-15"},"imported":[{"uid":"a10d-4"},{"uid":"a10d-6"},{"uid":"a10d-8"},{"uid":"a10d-10"},{"uid":"a10d-12"},{"uid":"a10d-0"}],"importedBy":[],"isEntry":true},"a10d-16":{"id":"@tanstack/react-query","moduleParts":{},"imported":[],"importedBy":[{"uid":"a10d-4"},{"uid":"a10d-6"},{"uid":"a10d-8"},{"uid":"a10d-10"},{"uid":"a10d-12"},{"uid":"a10d-0"}],"isExternal":true}},"env":{"rollup":"2.77.2"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
4017
+ const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"name":"src","children":[{"uid":"6cf5-1","name":"utils.ts"},{"uid":"6cf5-3","name":"createBaseQuery.ts"},{"uid":"6cf5-5","name":"createQuery.tsx"},{"uid":"6cf5-7","name":"createSuspenseQuery.ts"},{"uid":"6cf5-9","name":"createInfiniteQuery.ts"},{"uid":"6cf5-11","name":"createSuspenseInfiniteQuery.ts"},{"uid":"6cf5-13","name":"createMutation.ts"},{"uid":"6cf5-15","name":"index.ts"}]}]}],"isRoot":true},"nodeParts":{"6cf5-1":{"renderedLength":831,"gzipLength":395,"brotliLength":0,"mainUid":"6cf5-0"},"6cf5-3":{"renderedLength":999,"gzipLength":361,"brotliLength":0,"mainUid":"6cf5-2"},"6cf5-5":{"renderedLength":97,"gzipLength":90,"brotliLength":0,"mainUid":"6cf5-4"},"6cf5-7":{"renderedLength":271,"gzipLength":177,"brotliLength":0,"mainUid":"6cf5-6"},"6cf5-9":{"renderedLength":113,"gzipLength":99,"brotliLength":0,"mainUid":"6cf5-8"},"6cf5-11":{"renderedLength":287,"gzipLength":186,"brotliLength":0,"mainUid":"6cf5-10"},"6cf5-13":{"renderedLength":265,"gzipLength":173,"brotliLength":0,"mainUid":"6cf5-12"},"6cf5-15":{"renderedLength":0,"gzipLength":0,"brotliLength":0,"mainUid":"6cf5-14"}},"nodeMetas":{"6cf5-0":{"id":"/src/utils.ts","moduleParts":{"index.production.js":"6cf5-1"},"imported":[{"uid":"6cf5-16"}],"importedBy":[{"uid":"6cf5-14"},{"uid":"6cf5-12"},{"uid":"6cf5-2"}]},"6cf5-2":{"id":"/src/createBaseQuery.ts","moduleParts":{"index.production.js":"6cf5-3"},"imported":[{"uid":"6cf5-0"}],"importedBy":[{"uid":"6cf5-4"},{"uid":"6cf5-6"},{"uid":"6cf5-8"},{"uid":"6cf5-10"}]},"6cf5-4":{"id":"/src/createQuery.tsx","moduleParts":{"index.production.js":"6cf5-5"},"imported":[{"uid":"6cf5-16"},{"uid":"6cf5-2"}],"importedBy":[{"uid":"6cf5-14"}]},"6cf5-6":{"id":"/src/createSuspenseQuery.ts","moduleParts":{"index.production.js":"6cf5-7"},"imported":[{"uid":"6cf5-16"},{"uid":"6cf5-2"}],"importedBy":[{"uid":"6cf5-14"}]},"6cf5-8":{"id":"/src/createInfiniteQuery.ts","moduleParts":{"index.production.js":"6cf5-9"},"imported":[{"uid":"6cf5-16"},{"uid":"6cf5-2"}],"importedBy":[{"uid":"6cf5-14"}]},"6cf5-10":{"id":"/src/createSuspenseInfiniteQuery.ts","moduleParts":{"index.production.js":"6cf5-11"},"imported":[{"uid":"6cf5-16"},{"uid":"6cf5-2"}],"importedBy":[{"uid":"6cf5-14"}]},"6cf5-12":{"id":"/src/createMutation.ts","moduleParts":{"index.production.js":"6cf5-13"},"imported":[{"uid":"6cf5-16"},{"uid":"6cf5-0"}],"importedBy":[{"uid":"6cf5-14"}]},"6cf5-14":{"id":"/src/index.ts","moduleParts":{"index.production.js":"6cf5-15"},"imported":[{"uid":"6cf5-4"},{"uid":"6cf5-6"},{"uid":"6cf5-8"},{"uid":"6cf5-10"},{"uid":"6cf5-12"},{"uid":"6cf5-0"}],"importedBy":[],"isEntry":true},"6cf5-16":{"id":"@tanstack/react-query","moduleParts":{},"imported":[],"importedBy":[{"uid":"6cf5-4"},{"uid":"6cf5-6"},{"uid":"6cf5-8"},{"uid":"6cf5-10"},{"uid":"6cf5-12"},{"uid":"6cf5-0"}],"isExternal":true}},"env":{"rollup":"2.77.2"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
4018
4018
 
4019
4019
  const run = () => {
4020
4020
  const width = window.innerWidth;
package/build/stats.json CHANGED
@@ -10,35 +10,35 @@
10
10
  "name": "src",
11
11
  "children": [
12
12
  {
13
- "uid": "a10d-18",
13
+ "uid": "6cf5-18",
14
14
  "name": "utils.ts"
15
15
  },
16
16
  {
17
- "uid": "a10d-20",
17
+ "uid": "6cf5-20",
18
18
  "name": "createBaseQuery.ts"
19
19
  },
20
20
  {
21
- "uid": "a10d-22",
21
+ "uid": "6cf5-22",
22
22
  "name": "createQuery.tsx"
23
23
  },
24
24
  {
25
- "uid": "a10d-24",
25
+ "uid": "6cf5-24",
26
26
  "name": "createSuspenseQuery.ts"
27
27
  },
28
28
  {
29
- "uid": "a10d-26",
29
+ "uid": "6cf5-26",
30
30
  "name": "createInfiniteQuery.ts"
31
31
  },
32
32
  {
33
- "uid": "a10d-28",
33
+ "uid": "6cf5-28",
34
34
  "name": "createSuspenseInfiniteQuery.ts"
35
35
  },
36
36
  {
37
- "uid": "a10d-30",
37
+ "uid": "6cf5-30",
38
38
  "name": "createMutation.ts"
39
39
  },
40
40
  {
41
- "uid": "a10d-32",
41
+ "uid": "6cf5-32",
42
42
  "name": "index.ts"
43
43
  }
44
44
  ]
@@ -49,248 +49,248 @@
49
49
  "isRoot": true
50
50
  },
51
51
  "nodeParts": {
52
- "a10d-18": {
52
+ "6cf5-18": {
53
53
  "renderedLength": 831,
54
54
  "gzipLength": 395,
55
55
  "brotliLength": 0,
56
- "mainUid": "a10d-17"
56
+ "mainUid": "6cf5-17"
57
57
  },
58
- "a10d-20": {
58
+ "6cf5-20": {
59
59
  "renderedLength": 999,
60
60
  "gzipLength": 361,
61
61
  "brotliLength": 0,
62
- "mainUid": "a10d-19"
62
+ "mainUid": "6cf5-19"
63
63
  },
64
- "a10d-22": {
64
+ "6cf5-22": {
65
65
  "renderedLength": 97,
66
66
  "gzipLength": 90,
67
67
  "brotliLength": 0,
68
- "mainUid": "a10d-21"
68
+ "mainUid": "6cf5-21"
69
69
  },
70
- "a10d-24": {
70
+ "6cf5-24": {
71
71
  "renderedLength": 271,
72
72
  "gzipLength": 177,
73
73
  "brotliLength": 0,
74
- "mainUid": "a10d-23"
74
+ "mainUid": "6cf5-23"
75
75
  },
76
- "a10d-26": {
76
+ "6cf5-26": {
77
77
  "renderedLength": 113,
78
78
  "gzipLength": 99,
79
79
  "brotliLength": 0,
80
- "mainUid": "a10d-25"
80
+ "mainUid": "6cf5-25"
81
81
  },
82
- "a10d-28": {
82
+ "6cf5-28": {
83
83
  "renderedLength": 287,
84
84
  "gzipLength": 186,
85
85
  "brotliLength": 0,
86
- "mainUid": "a10d-27"
86
+ "mainUid": "6cf5-27"
87
87
  },
88
- "a10d-30": {
88
+ "6cf5-30": {
89
89
  "renderedLength": 265,
90
90
  "gzipLength": 173,
91
91
  "brotliLength": 0,
92
- "mainUid": "a10d-29"
92
+ "mainUid": "6cf5-29"
93
93
  },
94
- "a10d-32": {
94
+ "6cf5-32": {
95
95
  "renderedLength": 0,
96
96
  "gzipLength": 0,
97
97
  "brotliLength": 0,
98
- "mainUid": "a10d-31"
98
+ "mainUid": "6cf5-31"
99
99
  }
100
100
  },
101
101
  "nodeMetas": {
102
- "a10d-17": {
102
+ "6cf5-17": {
103
103
  "id": "/src/utils.ts",
104
104
  "moduleParts": {
105
- "index.production.js": "a10d-18"
105
+ "index.production.js": "6cf5-18"
106
106
  },
107
107
  "imported": [
108
108
  {
109
- "uid": "a10d-33"
109
+ "uid": "6cf5-33"
110
110
  }
111
111
  ],
112
112
  "importedBy": [
113
113
  {
114
- "uid": "a10d-31"
114
+ "uid": "6cf5-31"
115
115
  },
116
116
  {
117
- "uid": "a10d-29"
117
+ "uid": "6cf5-29"
118
118
  },
119
119
  {
120
- "uid": "a10d-19"
120
+ "uid": "6cf5-19"
121
121
  }
122
122
  ]
123
123
  },
124
- "a10d-19": {
124
+ "6cf5-19": {
125
125
  "id": "/src/createBaseQuery.ts",
126
126
  "moduleParts": {
127
- "index.production.js": "a10d-20"
127
+ "index.production.js": "6cf5-20"
128
128
  },
129
129
  "imported": [
130
130
  {
131
- "uid": "a10d-17"
131
+ "uid": "6cf5-17"
132
132
  }
133
133
  ],
134
134
  "importedBy": [
135
135
  {
136
- "uid": "a10d-21"
136
+ "uid": "6cf5-21"
137
137
  },
138
138
  {
139
- "uid": "a10d-23"
139
+ "uid": "6cf5-23"
140
140
  },
141
141
  {
142
- "uid": "a10d-25"
142
+ "uid": "6cf5-25"
143
143
  },
144
144
  {
145
- "uid": "a10d-27"
145
+ "uid": "6cf5-27"
146
146
  }
147
147
  ]
148
148
  },
149
- "a10d-21": {
149
+ "6cf5-21": {
150
150
  "id": "/src/createQuery.tsx",
151
151
  "moduleParts": {
152
- "index.production.js": "a10d-22"
152
+ "index.production.js": "6cf5-22"
153
153
  },
154
154
  "imported": [
155
155
  {
156
- "uid": "a10d-33"
156
+ "uid": "6cf5-33"
157
157
  },
158
158
  {
159
- "uid": "a10d-19"
159
+ "uid": "6cf5-19"
160
160
  }
161
161
  ],
162
162
  "importedBy": [
163
163
  {
164
- "uid": "a10d-31"
164
+ "uid": "6cf5-31"
165
165
  }
166
166
  ]
167
167
  },
168
- "a10d-23": {
168
+ "6cf5-23": {
169
169
  "id": "/src/createSuspenseQuery.ts",
170
170
  "moduleParts": {
171
- "index.production.js": "a10d-24"
171
+ "index.production.js": "6cf5-24"
172
172
  },
173
173
  "imported": [
174
174
  {
175
- "uid": "a10d-33"
175
+ "uid": "6cf5-33"
176
176
  },
177
177
  {
178
- "uid": "a10d-19"
178
+ "uid": "6cf5-19"
179
179
  }
180
180
  ],
181
181
  "importedBy": [
182
182
  {
183
- "uid": "a10d-31"
183
+ "uid": "6cf5-31"
184
184
  }
185
185
  ]
186
186
  },
187
- "a10d-25": {
187
+ "6cf5-25": {
188
188
  "id": "/src/createInfiniteQuery.ts",
189
189
  "moduleParts": {
190
- "index.production.js": "a10d-26"
190
+ "index.production.js": "6cf5-26"
191
191
  },
192
192
  "imported": [
193
193
  {
194
- "uid": "a10d-33"
194
+ "uid": "6cf5-33"
195
195
  },
196
196
  {
197
- "uid": "a10d-19"
197
+ "uid": "6cf5-19"
198
198
  }
199
199
  ],
200
200
  "importedBy": [
201
201
  {
202
- "uid": "a10d-31"
202
+ "uid": "6cf5-31"
203
203
  }
204
204
  ]
205
205
  },
206
- "a10d-27": {
206
+ "6cf5-27": {
207
207
  "id": "/src/createSuspenseInfiniteQuery.ts",
208
208
  "moduleParts": {
209
- "index.production.js": "a10d-28"
209
+ "index.production.js": "6cf5-28"
210
210
  },
211
211
  "imported": [
212
212
  {
213
- "uid": "a10d-33"
213
+ "uid": "6cf5-33"
214
214
  },
215
215
  {
216
- "uid": "a10d-19"
216
+ "uid": "6cf5-19"
217
217
  }
218
218
  ],
219
219
  "importedBy": [
220
220
  {
221
- "uid": "a10d-31"
221
+ "uid": "6cf5-31"
222
222
  }
223
223
  ]
224
224
  },
225
- "a10d-29": {
225
+ "6cf5-29": {
226
226
  "id": "/src/createMutation.ts",
227
227
  "moduleParts": {
228
- "index.production.js": "a10d-30"
228
+ "index.production.js": "6cf5-30"
229
229
  },
230
230
  "imported": [
231
231
  {
232
- "uid": "a10d-33"
232
+ "uid": "6cf5-33"
233
233
  },
234
234
  {
235
- "uid": "a10d-17"
235
+ "uid": "6cf5-17"
236
236
  }
237
237
  ],
238
238
  "importedBy": [
239
239
  {
240
- "uid": "a10d-31"
240
+ "uid": "6cf5-31"
241
241
  }
242
242
  ]
243
243
  },
244
- "a10d-31": {
244
+ "6cf5-31": {
245
245
  "id": "/src/index.ts",
246
246
  "moduleParts": {
247
- "index.production.js": "a10d-32"
247
+ "index.production.js": "6cf5-32"
248
248
  },
249
249
  "imported": [
250
250
  {
251
- "uid": "a10d-21"
251
+ "uid": "6cf5-21"
252
252
  },
253
253
  {
254
- "uid": "a10d-23"
254
+ "uid": "6cf5-23"
255
255
  },
256
256
  {
257
- "uid": "a10d-25"
257
+ "uid": "6cf5-25"
258
258
  },
259
259
  {
260
- "uid": "a10d-27"
260
+ "uid": "6cf5-27"
261
261
  },
262
262
  {
263
- "uid": "a10d-29"
263
+ "uid": "6cf5-29"
264
264
  },
265
265
  {
266
- "uid": "a10d-17"
266
+ "uid": "6cf5-17"
267
267
  }
268
268
  ],
269
269
  "importedBy": [],
270
270
  "isEntry": true
271
271
  },
272
- "a10d-33": {
272
+ "6cf5-33": {
273
273
  "id": "@tanstack/react-query",
274
274
  "moduleParts": {},
275
275
  "imported": [],
276
276
  "importedBy": [
277
277
  {
278
- "uid": "a10d-21"
278
+ "uid": "6cf5-21"
279
279
  },
280
280
  {
281
- "uid": "a10d-23"
281
+ "uid": "6cf5-23"
282
282
  },
283
283
  {
284
- "uid": "a10d-25"
284
+ "uid": "6cf5-25"
285
285
  },
286
286
  {
287
- "uid": "a10d-27"
287
+ "uid": "6cf5-27"
288
288
  },
289
289
  {
290
- "uid": "a10d-29"
290
+ "uid": "6cf5-29"
291
291
  },
292
292
  {
293
- "uid": "a10d-17"
293
+ "uid": "6cf5-17"
294
294
  }
295
295
  ],
296
296
  "isExternal": true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-query-kit",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "🕊️ A toolkit for ReactQuery that make ReactQuery hooks more reusable and typesafe",
5
5
  "author": "liaoliao666",
6
6
  "repository": "liaoliao666/react-query-kit",
@@ -56,7 +56,7 @@
56
56
  "typescript": "^5.1.6"
57
57
  },
58
58
  "peerDependencies": {
59
- "@tanstack/react-query": ">= 4.0.0"
59
+ "@tanstack/react-query": "^4 || ^5"
60
60
  },
61
61
  "sideEffects": false,
62
62
  "scripts": {