react-query-kit 1.4.9 → 1.5.1
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 +89 -57
- package/build/lib/createBaseQuery.d.ts +1 -1
- package/build/lib/createBaseQuery.esm.js +31 -24
- package/build/lib/createBaseQuery.esm.js.map +1 -1
- package/build/lib/createBaseQuery.js +31 -24
- package/build/lib/createBaseQuery.js.map +1 -1
- package/build/lib/createBaseQuery.mjs +31 -24
- package/build/lib/createBaseQuery.mjs.map +1 -1
- package/build/lib/createImmutableQuery.d.ts +5 -12
- package/build/lib/createImmutableQuery.esm.js +2 -2
- package/build/lib/createImmutableQuery.esm.js.map +1 -1
- package/build/lib/createImmutableQuery.js +2 -2
- package/build/lib/createImmutableQuery.js.map +1 -1
- package/build/lib/createImmutableQuery.mjs +2 -2
- package/build/lib/createImmutableQuery.mjs.map +1 -1
- package/build/lib/createInfiniteQuery.d.ts +4 -12
- package/build/lib/createInfiniteQuery.esm.js +2 -2
- package/build/lib/createInfiniteQuery.esm.js.map +1 -1
- package/build/lib/createInfiniteQuery.js +2 -2
- package/build/lib/createInfiniteQuery.js.map +1 -1
- package/build/lib/createInfiniteQuery.mjs +2 -2
- package/build/lib/createInfiniteQuery.mjs.map +1 -1
- package/build/lib/createMutation.d.ts +5 -5
- package/build/lib/createMutation.esm.js +3 -12
- package/build/lib/createMutation.esm.js.map +1 -1
- package/build/lib/createMutation.js +3 -12
- package/build/lib/createMutation.js.map +1 -1
- package/build/lib/createMutation.mjs +3 -12
- package/build/lib/createMutation.mjs.map +1 -1
- package/build/lib/createQuery.d.ts +5 -12
- package/build/lib/createQuery.esm.js +2 -2
- package/build/lib/createQuery.esm.js.map +1 -1
- package/build/lib/createQuery.js +2 -2
- package/build/lib/createQuery.js.map +1 -1
- package/build/lib/createQuery.mjs +2 -2
- package/build/lib/createQuery.mjs.map +1 -1
- package/build/lib/createSuspenseInfiniteQuery.d.ts +4 -12
- package/build/lib/createSuspenseInfiniteQuery.esm.js +2 -2
- package/build/lib/createSuspenseInfiniteQuery.esm.js.map +1 -1
- package/build/lib/createSuspenseInfiniteQuery.js +2 -2
- package/build/lib/createSuspenseInfiniteQuery.js.map +1 -1
- package/build/lib/createSuspenseInfiniteQuery.mjs +2 -2
- package/build/lib/createSuspenseInfiniteQuery.mjs.map +1 -1
- package/build/lib/createSuspenseQuery.d.ts +5 -12
- package/build/lib/createSuspenseQuery.esm.js +2 -2
- package/build/lib/createSuspenseQuery.esm.js.map +1 -1
- package/build/lib/createSuspenseQuery.js +2 -2
- package/build/lib/createSuspenseQuery.js.map +1 -1
- package/build/lib/createSuspenseQuery.mjs +2 -2
- package/build/lib/createSuspenseQuery.mjs.map +1 -1
- package/build/lib/index.d.ts +2 -1
- package/build/lib/index.esm.js +1 -0
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.js +2 -0
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +1 -0
- package/build/lib/index.mjs.map +1 -1
- package/build/lib/types.d.ts +51 -36
- package/build/lib/utils.d.ts +8 -0
- package/build/lib/utils.esm.js +36 -0
- package/build/lib/utils.esm.js.map +1 -0
- package/build/lib/utils.js +42 -0
- package/build/lib/utils.js.map +1 -0
- package/build/lib/utils.mjs +36 -0
- package/build/lib/utils.mjs.map +1 -0
- package/build/stats-html.html +1 -1
- package/build/stats.json +129 -91
- package/build/umd/index.development.js +75 -45
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -1
- package/src/createBaseQuery.ts +51 -33
- package/src/createImmutableQuery.tsx +14 -42
- package/src/createInfiniteQuery.ts +13 -66
- package/src/createMutation.ts +21 -38
- package/src/createQuery.tsx +17 -34
- package/src/createSuspenseInfiniteQuery.ts +14 -73
- package/src/createSuspenseQuery.ts +17 -34
- package/src/index.ts +2 -0
- package/src/types.ts +146 -194
- package/src/utils.ts +45 -0
package/README.md
CHANGED
|
@@ -42,8 +42,8 @@ English | [简体中文](./README-zh_CN.md)
|
|
|
42
42
|
- [createSuspenseQuery](#createsuspensequery)
|
|
43
43
|
- [createSuspenseInfiniteQuery](#createsuspenseinfinitequery)
|
|
44
44
|
- [createMutation](#createmutation)
|
|
45
|
+
- [Middleware](#middleware)
|
|
45
46
|
- [Type inference](#type-inference)
|
|
46
|
-
- [Caution](#caution)
|
|
47
47
|
- [Issues](#issues)
|
|
48
48
|
- [🐛 Bugs](#-bugs)
|
|
49
49
|
- [💡 Feature Requests](#-feature-requests)
|
|
@@ -89,13 +89,8 @@ const usePost = createQuery<Response, Variables, Error>({
|
|
|
89
89
|
// if u only wanna fetch once
|
|
90
90
|
enabled: (data) => !data,
|
|
91
91
|
suspense: true,
|
|
92
|
-
// u can also pass
|
|
93
|
-
|
|
94
|
-
const { id } = useSomething()
|
|
95
|
-
return {
|
|
96
|
-
variables: { id }
|
|
97
|
-
}
|
|
98
|
-
}
|
|
92
|
+
// u can also pass middleware to cutomize this hook's behavior
|
|
93
|
+
use: [myMiddleware]
|
|
99
94
|
})
|
|
100
95
|
|
|
101
96
|
|
|
@@ -121,10 +116,7 @@ console.log(usePost.getKey(variables)) // ['/posts', { id: 1 }]
|
|
|
121
116
|
export async function getStaticProps() {
|
|
122
117
|
const queryClient = new QueryClient()
|
|
123
118
|
|
|
124
|
-
await queryClient.prefetchQuery(
|
|
125
|
-
queryKey: usePost.getKey(variables),
|
|
126
|
-
queryFn: usePost.queryFn
|
|
127
|
-
})
|
|
119
|
+
await queryClient.prefetchQuery(usePost.getFetchOptions(variables))
|
|
128
120
|
|
|
129
121
|
return {
|
|
130
122
|
props: {
|
|
@@ -134,16 +126,13 @@ export async function getStaticProps() {
|
|
|
134
126
|
}
|
|
135
127
|
|
|
136
128
|
// usage outside of react component
|
|
137
|
-
const data = await queryClient.fetchQuery(
|
|
138
|
-
queryKey: usePost.getKey(variables),
|
|
139
|
-
queryFn: usePost.queryFn
|
|
140
|
-
})
|
|
129
|
+
const data = await queryClient.fetchQuery(usePost.getFetchOptions(variables))
|
|
141
130
|
|
|
142
131
|
// useQueries example
|
|
143
132
|
const queries = useQueries({
|
|
144
133
|
queries: [
|
|
145
|
-
|
|
146
|
-
|
|
134
|
+
usePost.getFetchOptions(variables),
|
|
135
|
+
useProjects.getFetchOptions(),
|
|
147
136
|
],
|
|
148
137
|
})
|
|
149
138
|
|
|
@@ -162,14 +151,15 @@ Options
|
|
|
162
151
|
- Optional
|
|
163
152
|
- Set this to `false` to disable this query from automatically running.
|
|
164
153
|
- If set to a function, the function will be executed with the latest data to compute the boolean
|
|
165
|
-
- `
|
|
154
|
+
- `use: Middleware[]`
|
|
166
155
|
- Optional
|
|
167
|
-
-
|
|
156
|
+
- array of middleware functions [(details)](#middleware)
|
|
168
157
|
|
|
169
158
|
Expose Methods
|
|
170
159
|
|
|
171
160
|
- `getPrimaryKey: () => primaryKey`
|
|
172
161
|
- `getKey: (variables: TVariables) => [primaryKey, variables]`
|
|
162
|
+
- `getFetchOptions: (variables: TVariables) => {queryKey, queryFn, queryKeyHashFn}`
|
|
173
163
|
- `queryFn: QueryFunction<TFnData, [primaryKey, TVariables]>`
|
|
174
164
|
- `queryKeyHashFn: (queryKey: [primaryKey, TVariables]) => string`
|
|
175
165
|
|
|
@@ -201,7 +191,7 @@ const useProjects = createInfiniteQuery<Response, Variables, Error>({
|
|
|
201
191
|
).then(res => res.json())
|
|
202
192
|
},
|
|
203
193
|
getNextPageParam: (lastPage, pages) => lastPage.nextCursor,
|
|
204
|
-
|
|
194
|
+
initialPageParam: 1,
|
|
205
195
|
})
|
|
206
196
|
|
|
207
197
|
const variables = { active: true }
|
|
@@ -242,10 +232,7 @@ export default function Page() {
|
|
|
242
232
|
export async function getStaticProps() {
|
|
243
233
|
const queryClient = new QueryClient()
|
|
244
234
|
|
|
245
|
-
await queryClient.prefetchInfiniteQuery(
|
|
246
|
-
queryKey: useProjects.getKey(variables),
|
|
247
|
-
queryFn: useProjects.queryFn,
|
|
248
|
-
})
|
|
235
|
+
await queryClient.prefetchInfiniteQuery(useProjects.getFetchOptions(variables))
|
|
249
236
|
|
|
250
237
|
return {
|
|
251
238
|
props: {
|
|
@@ -255,16 +242,10 @@ export async function getStaticProps() {
|
|
|
255
242
|
}
|
|
256
243
|
|
|
257
244
|
// usage outside of react component
|
|
258
|
-
const data = await queryClient.fetchInfiniteQuery(
|
|
259
|
-
queryKey: useProjects.getKey(variables),
|
|
260
|
-
queryFn: useProjects.queryFn,
|
|
261
|
-
})
|
|
245
|
+
const data = await queryClient.fetchInfiniteQuery(useProjects.getFetchOptions(variables))
|
|
262
246
|
|
|
263
247
|
// usage outside of react component
|
|
264
|
-
const data = await queryClient.fetchInfiniteQuery(
|
|
265
|
-
queryKey: useProjects.getKey(variables),
|
|
266
|
-
queryFn: useProjects.queryFn,
|
|
267
|
-
})
|
|
248
|
+
const data = await queryClient.fetchInfiniteQuery(useProjects.getFetchOptions(variables))
|
|
268
249
|
```
|
|
269
250
|
|
|
270
251
|
### Additional API Reference
|
|
@@ -278,14 +259,15 @@ Options
|
|
|
278
259
|
- Optional
|
|
279
260
|
- Set this to `false` to disable this query from automatically running.
|
|
280
261
|
- If set to a function, the function will be executed with the latest data to compute the boolean
|
|
281
|
-
- `
|
|
262
|
+
- `use: Middleware[]`
|
|
282
263
|
- Optional
|
|
283
|
-
-
|
|
264
|
+
- array of middleware functions [(details)](#middleware)
|
|
284
265
|
|
|
285
266
|
Expose Methods
|
|
286
267
|
|
|
287
268
|
- `getPrimaryKey: () => primaryKey`
|
|
288
269
|
- `getKey: (variables: TVariables) => [primaryKey, variables]`
|
|
270
|
+
- `getFetchOptions: (variables: TVariables) => {queryKey, queryFn, queryKeyHashFn, getNextPageParam, getPreviousPageParam, initialPageParam}`
|
|
289
271
|
- `queryFn: QueryFunction<TFnData, [primaryKey, TVariables]>`
|
|
290
272
|
- `queryKeyHashFn: (queryKey: [primaryKey, TVariables]) => string`
|
|
291
273
|
|
|
@@ -422,47 +404,97 @@ useAddTodo.mutationFn({ title: 'Do Laundry', content: 'content...' })
|
|
|
422
404
|
|
|
423
405
|
Options
|
|
424
406
|
|
|
425
|
-
- `
|
|
407
|
+
- `use: Middleware[]`
|
|
426
408
|
- Optional
|
|
427
|
-
-
|
|
409
|
+
- array of middleware functions [(details)](#middleware)
|
|
428
410
|
|
|
429
411
|
Returns
|
|
430
412
|
|
|
431
413
|
- `getKey: () => MutationKey`
|
|
432
414
|
- `mutationFn: MutationFunction<TData, TVariables>`
|
|
433
415
|
|
|
434
|
-
##
|
|
416
|
+
## Middleware
|
|
435
417
|
|
|
436
|
-
|
|
418
|
+
This feature is inspired by the [Middleware feature from SWR](https://swr.vercel.app/docs/middleware). The middleware feature is a new addition in ReactQueryKit 1.5.0 that enables you to execute logic before and after hooks.
|
|
419
|
+
|
|
420
|
+
Middleware receive the hook and can execute logic before and after running it. If there are multiple middleware, each middleware wraps the next middleware. The last middleware in the list will receive the original hook.
|
|
421
|
+
|
|
422
|
+
### Usage
|
|
437
423
|
|
|
438
424
|
```ts
|
|
439
|
-
import {
|
|
425
|
+
import { Middleware, MutationHook, QueryHook } from 'react-query-kit'
|
|
426
|
+
|
|
427
|
+
const myMiddleware: Middleware<
|
|
428
|
+
QueryHook<Response, Variables>
|
|
429
|
+
> = useQueryNext => {
|
|
430
|
+
return options => {
|
|
431
|
+
const { userId } = useAuth()
|
|
432
|
+
return useQueryNext({
|
|
433
|
+
...options,
|
|
434
|
+
variables: options.variables ?? { id: userId },
|
|
435
|
+
})
|
|
436
|
+
}
|
|
437
|
+
}
|
|
440
438
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
439
|
+
const useUser = createQuery<Response, Variables>({
|
|
440
|
+
// ...
|
|
441
|
+
use: [myMiddleware],
|
|
442
|
+
})
|
|
443
|
+
|
|
444
|
+
// global middlewares
|
|
445
|
+
const queryMiddleware: Middleware<QueryHook> = useQueryNext => {
|
|
446
|
+
return options => {
|
|
447
|
+
// ...
|
|
448
|
+
return useQueryNext(options)
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
const mutationMiddleware: Middleware<MutationHook> = useMutationNext => {
|
|
452
|
+
return options => {
|
|
453
|
+
// ...
|
|
454
|
+
return useMutationNext(options)
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
const queryClient = createQueryClient({
|
|
459
|
+
queries: {
|
|
460
|
+
use: [queryMiddleware],
|
|
461
|
+
},
|
|
462
|
+
mutations: {
|
|
463
|
+
use: [mutationMiddleware],
|
|
464
|
+
},
|
|
465
|
+
})
|
|
444
466
|
```
|
|
445
467
|
|
|
446
|
-
|
|
468
|
+
### Multiple Middleware
|
|
447
469
|
|
|
448
|
-
|
|
470
|
+
Each middleware wraps the next middleware, and the last one just wraps the useQuery. For example:
|
|
449
471
|
|
|
450
|
-
```
|
|
451
|
-
|
|
452
|
-
usePost({
|
|
453
|
-
// This will not throw type errors
|
|
454
|
-
variables: {foo: 1}
|
|
455
|
-
})
|
|
472
|
+
```jsx
|
|
473
|
+
createQuery({ use: [a, b, c] })
|
|
456
474
|
```
|
|
457
475
|
|
|
458
|
-
|
|
476
|
+
The order of middleware executions will be a → b → c, as shown below:
|
|
477
|
+
|
|
478
|
+
```plaintext
|
|
479
|
+
enter a
|
|
480
|
+
enter b
|
|
481
|
+
enter c
|
|
482
|
+
useQuery()
|
|
483
|
+
exit c
|
|
484
|
+
exit b
|
|
485
|
+
exit a
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
## Type inference
|
|
489
|
+
|
|
490
|
+
You can extract the TypeScript type of any custom hook with `inferVariables` or `inferData`
|
|
459
491
|
|
|
460
492
|
```ts
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
493
|
+
import { inferData, inferFnData, inferVariables } from 'react-query-kit'
|
|
494
|
+
|
|
495
|
+
type Variables = inferVariables<typeof usePost>
|
|
496
|
+
type Data = inferData<typeof usePost>
|
|
497
|
+
type FnData = inferFnData<typeof usePost>
|
|
466
498
|
```
|
|
467
499
|
|
|
468
500
|
## Issues
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { UseBaseQueryOptions } from '@tanstack/react-query';
|
|
2
2
|
import type { AdditionalQueryHookOptions } from './types';
|
|
3
3
|
type QueryBaseHookOptions = Omit<UseBaseQueryOptions, 'queryKey' | 'queryFn' | 'enabled'> & AdditionalQueryHookOptions<any, any>;
|
|
4
|
-
export declare function createBaseQuery(
|
|
4
|
+
export declare function createBaseQuery(defaultOptions: any, useRQHook: (options: any, queryClient?: any) => any, overrideOptions?: QueryBaseHookOptions): any;
|
|
5
5
|
export {};
|
|
@@ -1,52 +1,59 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { withMiddlewares, getQueryKey, useCompatibeQueryClient } from './utils.esm.js';
|
|
2
2
|
|
|
3
|
-
function createBaseQuery(
|
|
3
|
+
function createBaseQuery(defaultOptions, useRQHook, overrideOptions) {
|
|
4
4
|
const {
|
|
5
|
-
primaryKey
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
primaryKey
|
|
6
|
+
} = defaultOptions;
|
|
7
|
+
|
|
8
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
if (defaultOptions.useDefaultOptions) {
|
|
11
|
+
throw new Error('useDefaultOptions is not supported, please use middleware instead.');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
11
14
|
|
|
12
15
|
const getPrimaryKey = () => primaryKey;
|
|
13
16
|
|
|
14
|
-
const getKey = variables =>
|
|
17
|
+
const getKey = variables => getQueryKey(primaryKey, variables);
|
|
18
|
+
|
|
19
|
+
const getFetchOptions = variables => {
|
|
20
|
+
return {
|
|
21
|
+
queryKey: getKey(variables),
|
|
22
|
+
queryFn: defaultOptions.queryFn,
|
|
23
|
+
queryKeyHashFn: defaultOptions.queryKeyHashFn,
|
|
24
|
+
getPreviousPageParam: defaultOptions.getPreviousPageParam,
|
|
25
|
+
getNextPageParam: defaultOptions.getNextPageParam,
|
|
26
|
+
initialPageParam: defaultOptions.initialPageParam
|
|
27
|
+
};
|
|
28
|
+
};
|
|
15
29
|
|
|
16
|
-
const useGeneratedQuery = options => {
|
|
30
|
+
const useGeneratedQuery = (options, queryClient) => {
|
|
31
|
+
const client = useCompatibeQueryClient(options, queryClient);
|
|
17
32
|
const {
|
|
18
33
|
enabled,
|
|
19
34
|
variables,
|
|
20
35
|
...mergedOptions
|
|
21
|
-
} = { ...
|
|
22
|
-
...(useDefaultOptions == null ? void 0 : useDefaultOptions()),
|
|
23
|
-
...options,
|
|
36
|
+
} = { ...options,
|
|
24
37
|
...overrideOptions
|
|
25
38
|
};
|
|
26
39
|
const queryKey = getKey(variables);
|
|
27
|
-
const client = useQueryClient( // compatible with ReactQuery v4
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
mergedOptions.context ? {
|
|
30
|
-
context: mergedOptions.context
|
|
31
|
-
} : queryClient);
|
|
32
40
|
const result = useRQHook({ ...mergedOptions,
|
|
33
41
|
enabled: typeof enabled === 'function' ? enabled(client.getQueryData(queryKey), variables) : enabled,
|
|
34
|
-
queryKeyHashFn,
|
|
35
|
-
queryFn,
|
|
36
42
|
queryKey
|
|
37
43
|
}, client);
|
|
38
44
|
return Object.assign(result, {
|
|
39
|
-
queryKey,
|
|
45
|
+
queryKey: queryKey,
|
|
40
46
|
variables,
|
|
41
47
|
setData: (updater, setDataOptions) => client.setQueryData(queryKey, updater, setDataOptions)
|
|
42
48
|
});
|
|
43
49
|
};
|
|
44
50
|
|
|
45
|
-
return Object.assign(useGeneratedQuery, {
|
|
51
|
+
return Object.assign(withMiddlewares(useGeneratedQuery, defaultOptions, 'queries'), {
|
|
46
52
|
getPrimaryKey,
|
|
47
53
|
getKey,
|
|
48
|
-
queryFn,
|
|
49
|
-
queryKeyHashFn
|
|
54
|
+
queryFn: defaultOptions.queryFn,
|
|
55
|
+
queryKeyHashFn: defaultOptions.queryKeyHashFn,
|
|
56
|
+
getFetchOptions
|
|
50
57
|
});
|
|
51
58
|
}
|
|
52
59
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBaseQuery.esm.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"createBaseQuery.esm.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {\n QueryClient,\n SetDataOptions,\n Updater,\n UseBaseQueryOptions,\n} from '@tanstack/react-query'\n\nimport type {\n AdditionalCreateOptions,\n AdditionalQueryHookOptions,\n CompatibleWithV4,\n Middleware,\n} from './types'\nimport { getQueryKey, useCompatibeQueryClient, withMiddlewares } from './utils'\n\ninterface CreateQueryOptions\n extends Omit<UseBaseQueryOptions, 'queryKey' | 'queryFn' | 'enabled'>,\n AdditionalCreateOptions<any, any> {\n use?: Middleware[]\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn' | 'enabled'\n> &\n AdditionalQueryHookOptions<any, any>\n\nexport function createBaseQuery(\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: QueryBaseHookOptions\n): any {\n const { primaryKey } = defaultOptions as CreateQueryOptions\n\n if (process.env.NODE_ENV !== 'production') {\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n throw new Error(\n 'useDefaultOptions is not supported, please use middleware instead.'\n )\n }\n }\n\n const getPrimaryKey = () => primaryKey\n\n const getKey = (variables?: any) => getQueryKey(primaryKey, variables)\n\n const getFetchOptions = (variables: any) => {\n return {\n queryKey: getKey(variables),\n queryFn: defaultOptions.queryFn,\n queryKeyHashFn: defaultOptions.queryKeyHashFn,\n getPreviousPageParam: (defaultOptions as any).getPreviousPageParam,\n getNextPageParam: (defaultOptions as any).getNextPageParam,\n initialPageParam: (defaultOptions as any).initialPageParam,\n }\n }\n\n const useGeneratedQuery = (\n options: QueryBaseHookOptions,\n queryClient?: CompatibleWithV4<QueryClient, void>\n ) => {\n const client = useCompatibeQueryClient(options, queryClient)\n\n const { enabled, variables, ...mergedOptions } = {\n ...options,\n ...overrideOptions,\n } as QueryBaseHookOptions\n\n const queryKey = getKey(variables)\n\n const result = useRQHook(\n {\n ...mergedOptions,\n enabled:\n typeof enabled === 'function'\n ? enabled(client.getQueryData(queryKey), variables)\n : enabled,\n queryKey,\n },\n client\n )\n\n return Object.assign(result, {\n queryKey: queryKey,\n variables,\n setData: (updater: Updater<any, any>, setDataOptions?: SetDataOptions) =>\n client.setQueryData(queryKey, updater, setDataOptions),\n })\n }\n\n return Object.assign(\n withMiddlewares(useGeneratedQuery, defaultOptions, 'queries'),\n {\n getPrimaryKey,\n getKey,\n queryFn: defaultOptions.queryFn,\n queryKeyHashFn: defaultOptions.queryKeyHashFn,\n getFetchOptions,\n }\n )\n}\n"],"names":["createBaseQuery","defaultOptions","useRQHook","overrideOptions","primaryKey","process","env","NODE_ENV","useDefaultOptions","Error","getPrimaryKey","getKey","variables","getQueryKey","getFetchOptions","queryKey","queryFn","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","useGeneratedQuery","options","queryClient","client","useCompatibeQueryClient","enabled","mergedOptions","result","getQueryData","Object","assign","setData","updater","setDataOptions","setQueryData","withMiddlewares"],"mappings":";;AA2BO,SAASA,eAAT,CACLC,cADK,EAELC,SAFK,EAGLC,eAHK,EAIA;EACL,MAAM;AAAEC,IAAAA,UAAAA;AAAF,GAAA,GAAiBH,cAAvB,CAAA;;AAEA,EAAA,IAAII,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC;IACA,IAAIN,cAAc,CAACO,iBAAnB,EAAsC;AACpC,MAAA,MAAM,IAAIC,KAAJ,CACJ,oEADI,CAAN,CAAA;AAGD,KAAA;AACF,GAAA;;EAED,MAAMC,aAAa,GAAG,MAAMN,UAA5B,CAAA;;EAEA,MAAMO,MAAM,GAAIC,SAAD,IAAqBC,WAA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AAvC,CAAA;AAJyB,KAAtB,CAAP,CAAA;GAzBF,CAAA;;AAiCA,EAAA,OAAOJ,MAAM,CAACC,MAAP,CACLK,eAAe,CAACf,iBAAD,EAAoBpB,cAApB,EAAoC,SAApC,CADV,EAEL;IACES,aADF;IAEEC,MAFF;IAGEK,OAAO,EAAEf,cAAc,CAACe,OAH1B;IAIEC,cAAc,EAAEhB,cAAc,CAACgB,cAJjC;AAKEH,IAAAA,eAAAA;AALF,GAFK,CAAP,CAAA;AAUD;;;;"}
|
|
@@ -2,55 +2,62 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var utils = require('./utils.js');
|
|
6
6
|
|
|
7
|
-
function createBaseQuery(
|
|
7
|
+
function createBaseQuery(defaultOptions, useRQHook, overrideOptions) {
|
|
8
8
|
const {
|
|
9
|
-
primaryKey
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
primaryKey
|
|
10
|
+
} = defaultOptions;
|
|
11
|
+
|
|
12
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
if (defaultOptions.useDefaultOptions) {
|
|
15
|
+
throw new Error('useDefaultOptions is not supported, please use middleware instead.');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
15
18
|
|
|
16
19
|
const getPrimaryKey = () => primaryKey;
|
|
17
20
|
|
|
18
|
-
const getKey = variables =>
|
|
21
|
+
const getKey = variables => utils.getQueryKey(primaryKey, variables);
|
|
22
|
+
|
|
23
|
+
const getFetchOptions = variables => {
|
|
24
|
+
return {
|
|
25
|
+
queryKey: getKey(variables),
|
|
26
|
+
queryFn: defaultOptions.queryFn,
|
|
27
|
+
queryKeyHashFn: defaultOptions.queryKeyHashFn,
|
|
28
|
+
getPreviousPageParam: defaultOptions.getPreviousPageParam,
|
|
29
|
+
getNextPageParam: defaultOptions.getNextPageParam,
|
|
30
|
+
initialPageParam: defaultOptions.initialPageParam
|
|
31
|
+
};
|
|
32
|
+
};
|
|
19
33
|
|
|
20
|
-
const useGeneratedQuery = options => {
|
|
34
|
+
const useGeneratedQuery = (options, queryClient) => {
|
|
35
|
+
const client = utils.useCompatibeQueryClient(options, queryClient);
|
|
21
36
|
const {
|
|
22
37
|
enabled,
|
|
23
38
|
variables,
|
|
24
39
|
...mergedOptions
|
|
25
|
-
} = { ...
|
|
26
|
-
...(useDefaultOptions == null ? void 0 : useDefaultOptions()),
|
|
27
|
-
...options,
|
|
40
|
+
} = { ...options,
|
|
28
41
|
...overrideOptions
|
|
29
42
|
};
|
|
30
43
|
const queryKey = getKey(variables);
|
|
31
|
-
const client = reactQuery.useQueryClient( // compatible with ReactQuery v4
|
|
32
|
-
// @ts-ignore
|
|
33
|
-
mergedOptions.context ? {
|
|
34
|
-
context: mergedOptions.context
|
|
35
|
-
} : queryClient);
|
|
36
44
|
const result = useRQHook({ ...mergedOptions,
|
|
37
45
|
enabled: typeof enabled === 'function' ? enabled(client.getQueryData(queryKey), variables) : enabled,
|
|
38
|
-
queryKeyHashFn,
|
|
39
|
-
queryFn,
|
|
40
46
|
queryKey
|
|
41
47
|
}, client);
|
|
42
48
|
return Object.assign(result, {
|
|
43
|
-
queryKey,
|
|
49
|
+
queryKey: queryKey,
|
|
44
50
|
variables,
|
|
45
51
|
setData: (updater, setDataOptions) => client.setQueryData(queryKey, updater, setDataOptions)
|
|
46
52
|
});
|
|
47
53
|
};
|
|
48
54
|
|
|
49
|
-
return Object.assign(useGeneratedQuery, {
|
|
55
|
+
return Object.assign(utils.withMiddlewares(useGeneratedQuery, defaultOptions, 'queries'), {
|
|
50
56
|
getPrimaryKey,
|
|
51
57
|
getKey,
|
|
52
|
-
queryFn,
|
|
53
|
-
queryKeyHashFn
|
|
58
|
+
queryFn: defaultOptions.queryFn,
|
|
59
|
+
queryKeyHashFn: defaultOptions.queryKeyHashFn,
|
|
60
|
+
getFetchOptions
|
|
54
61
|
});
|
|
55
62
|
}
|
|
56
63
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBaseQuery.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"createBaseQuery.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {\n QueryClient,\n SetDataOptions,\n Updater,\n UseBaseQueryOptions,\n} from '@tanstack/react-query'\n\nimport type {\n AdditionalCreateOptions,\n AdditionalQueryHookOptions,\n CompatibleWithV4,\n Middleware,\n} from './types'\nimport { getQueryKey, useCompatibeQueryClient, withMiddlewares } from './utils'\n\ninterface CreateQueryOptions\n extends Omit<UseBaseQueryOptions, 'queryKey' | 'queryFn' | 'enabled'>,\n AdditionalCreateOptions<any, any> {\n use?: Middleware[]\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn' | 'enabled'\n> &\n AdditionalQueryHookOptions<any, any>\n\nexport function createBaseQuery(\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: QueryBaseHookOptions\n): any {\n const { primaryKey } = defaultOptions as CreateQueryOptions\n\n if (process.env.NODE_ENV !== 'production') {\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n throw new Error(\n 'useDefaultOptions is not supported, please use middleware instead.'\n )\n }\n }\n\n const getPrimaryKey = () => primaryKey\n\n const getKey = (variables?: any) => getQueryKey(primaryKey, variables)\n\n const getFetchOptions = (variables: any) => {\n return {\n queryKey: getKey(variables),\n queryFn: defaultOptions.queryFn,\n queryKeyHashFn: defaultOptions.queryKeyHashFn,\n getPreviousPageParam: (defaultOptions as any).getPreviousPageParam,\n getNextPageParam: (defaultOptions as any).getNextPageParam,\n initialPageParam: (defaultOptions as any).initialPageParam,\n }\n }\n\n const useGeneratedQuery = (\n options: QueryBaseHookOptions,\n queryClient?: CompatibleWithV4<QueryClient, void>\n ) => {\n const client = useCompatibeQueryClient(options, queryClient)\n\n const { enabled, variables, ...mergedOptions } = {\n ...options,\n ...overrideOptions,\n } as QueryBaseHookOptions\n\n const queryKey = getKey(variables)\n\n const result = useRQHook(\n {\n ...mergedOptions,\n enabled:\n typeof enabled === 'function'\n ? enabled(client.getQueryData(queryKey), variables)\n : enabled,\n queryKey,\n },\n client\n )\n\n return Object.assign(result, {\n queryKey: queryKey,\n variables,\n setData: (updater: Updater<any, any>, setDataOptions?: SetDataOptions) =>\n client.setQueryData(queryKey, updater, setDataOptions),\n })\n }\n\n return Object.assign(\n withMiddlewares(useGeneratedQuery, defaultOptions, 'queries'),\n {\n getPrimaryKey,\n getKey,\n queryFn: defaultOptions.queryFn,\n queryKeyHashFn: defaultOptions.queryKeyHashFn,\n getFetchOptions,\n }\n )\n}\n"],"names":["createBaseQuery","defaultOptions","useRQHook","overrideOptions","primaryKey","process","env","NODE_ENV","useDefaultOptions","Error","getPrimaryKey","getKey","variables","getQueryKey","getFetchOptions","queryKey","queryFn","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","useGeneratedQuery","options","queryClient","client","useCompatibeQueryClient","enabled","mergedOptions","result","getQueryData","Object","assign","setData","updater","setDataOptions","setQueryData","withMiddlewares"],"mappings":";;;;;;AA2BO,SAASA,eAAT,CACLC,cADK,EAELC,SAFK,EAGLC,eAHK,EAIA;EACL,MAAM;AAAEC,IAAAA,UAAAA;AAAF,GAAA,GAAiBH,cAAvB,CAAA;;AAEA,EAAA,IAAII,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC;IACA,IAAIN,cAAc,CAACO,iBAAnB,EAAsC;AACpC,MAAA,MAAM,IAAIC,KAAJ,CACJ,oEADI,CAAN,CAAA;AAGD,KAAA;AACF,GAAA;;EAED,MAAMC,aAAa,GAAG,MAAMN,UAA5B,CAAA;;EAEA,MAAMO,MAAM,GAAIC,SAAD,IAAqBC,iBAAW,CAACT,UAAD,EAAaQ,SAAb,CAA/C,CAA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AzBF,CAAA;;AAiCA,EAAA,OAAOJ,MAAM,CAACC,MAAP,CACLK,qBAAe,CAACf,iBAAD,EAAoBpB,cAApB,EAAoC,SAApC,CADV,EAEL;IACES,aADF;IAEEC,MAFF;IAGEK,OAAO,EAAEf,cAAc,CAACe,OAH1B;IAIEC,cAAc,EAAEhB,cAAc,CAACgB,cAJjC;AAKEH,IAAAA,eAAAA;AALF,GAFK,CAAP,CAAA;AAUD;;;;"}
|
|
@@ -1,52 +1,59 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { withMiddlewares, getQueryKey, useCompatibeQueryClient } from './utils.mjs';
|
|
2
2
|
|
|
3
|
-
function createBaseQuery(
|
|
3
|
+
function createBaseQuery(defaultOptions, useRQHook, overrideOptions) {
|
|
4
4
|
const {
|
|
5
|
-
primaryKey
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
primaryKey
|
|
6
|
+
} = defaultOptions;
|
|
7
|
+
|
|
8
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
if (defaultOptions.useDefaultOptions) {
|
|
11
|
+
throw new Error('useDefaultOptions is not supported, please use middleware instead.');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
11
14
|
|
|
12
15
|
const getPrimaryKey = () => primaryKey;
|
|
13
16
|
|
|
14
|
-
const getKey = variables =>
|
|
17
|
+
const getKey = variables => getQueryKey(primaryKey, variables);
|
|
18
|
+
|
|
19
|
+
const getFetchOptions = variables => {
|
|
20
|
+
return {
|
|
21
|
+
queryKey: getKey(variables),
|
|
22
|
+
queryFn: defaultOptions.queryFn,
|
|
23
|
+
queryKeyHashFn: defaultOptions.queryKeyHashFn,
|
|
24
|
+
getPreviousPageParam: defaultOptions.getPreviousPageParam,
|
|
25
|
+
getNextPageParam: defaultOptions.getNextPageParam,
|
|
26
|
+
initialPageParam: defaultOptions.initialPageParam
|
|
27
|
+
};
|
|
28
|
+
};
|
|
15
29
|
|
|
16
|
-
const useGeneratedQuery = options => {
|
|
30
|
+
const useGeneratedQuery = (options, queryClient) => {
|
|
31
|
+
const client = useCompatibeQueryClient(options, queryClient);
|
|
17
32
|
const {
|
|
18
33
|
enabled,
|
|
19
34
|
variables,
|
|
20
35
|
...mergedOptions
|
|
21
|
-
} = { ...
|
|
22
|
-
...(useDefaultOptions == null ? void 0 : useDefaultOptions()),
|
|
23
|
-
...options,
|
|
36
|
+
} = { ...options,
|
|
24
37
|
...overrideOptions
|
|
25
38
|
};
|
|
26
39
|
const queryKey = getKey(variables);
|
|
27
|
-
const client = useQueryClient( // compatible with ReactQuery v4
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
mergedOptions.context ? {
|
|
30
|
-
context: mergedOptions.context
|
|
31
|
-
} : queryClient);
|
|
32
40
|
const result = useRQHook({ ...mergedOptions,
|
|
33
41
|
enabled: typeof enabled === 'function' ? enabled(client.getQueryData(queryKey), variables) : enabled,
|
|
34
|
-
queryKeyHashFn,
|
|
35
|
-
queryFn,
|
|
36
42
|
queryKey
|
|
37
43
|
}, client);
|
|
38
44
|
return Object.assign(result, {
|
|
39
|
-
queryKey,
|
|
45
|
+
queryKey: queryKey,
|
|
40
46
|
variables,
|
|
41
47
|
setData: (updater, setDataOptions) => client.setQueryData(queryKey, updater, setDataOptions)
|
|
42
48
|
});
|
|
43
49
|
};
|
|
44
50
|
|
|
45
|
-
return Object.assign(useGeneratedQuery, {
|
|
51
|
+
return Object.assign(withMiddlewares(useGeneratedQuery, defaultOptions, 'queries'), {
|
|
46
52
|
getPrimaryKey,
|
|
47
53
|
getKey,
|
|
48
|
-
queryFn,
|
|
49
|
-
queryKeyHashFn
|
|
54
|
+
queryFn: defaultOptions.queryFn,
|
|
55
|
+
queryKeyHashFn: defaultOptions.queryKeyHashFn,
|
|
56
|
+
getFetchOptions
|
|
50
57
|
});
|
|
51
58
|
}
|
|
52
59
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBaseQuery.mjs","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"createBaseQuery.mjs","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {\n QueryClient,\n SetDataOptions,\n Updater,\n UseBaseQueryOptions,\n} from '@tanstack/react-query'\n\nimport type {\n AdditionalCreateOptions,\n AdditionalQueryHookOptions,\n CompatibleWithV4,\n Middleware,\n} from './types'\nimport { getQueryKey, useCompatibeQueryClient, withMiddlewares } from './utils'\n\ninterface CreateQueryOptions\n extends Omit<UseBaseQueryOptions, 'queryKey' | 'queryFn' | 'enabled'>,\n AdditionalCreateOptions<any, any> {\n use?: Middleware[]\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn' | 'enabled'\n> &\n AdditionalQueryHookOptions<any, any>\n\nexport function createBaseQuery(\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: QueryBaseHookOptions\n): any {\n const { primaryKey } = defaultOptions as CreateQueryOptions\n\n if (process.env.NODE_ENV !== 'production') {\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n throw new Error(\n 'useDefaultOptions is not supported, please use middleware instead.'\n )\n }\n }\n\n const getPrimaryKey = () => primaryKey\n\n const getKey = (variables?: any) => getQueryKey(primaryKey, variables)\n\n const getFetchOptions = (variables: any) => {\n return {\n queryKey: getKey(variables),\n queryFn: defaultOptions.queryFn,\n queryKeyHashFn: defaultOptions.queryKeyHashFn,\n getPreviousPageParam: (defaultOptions as any).getPreviousPageParam,\n getNextPageParam: (defaultOptions as any).getNextPageParam,\n initialPageParam: (defaultOptions as any).initialPageParam,\n }\n }\n\n const useGeneratedQuery = (\n options: QueryBaseHookOptions,\n queryClient?: CompatibleWithV4<QueryClient, void>\n ) => {\n const client = useCompatibeQueryClient(options, queryClient)\n\n const { enabled, variables, ...mergedOptions } = {\n ...options,\n ...overrideOptions,\n } as QueryBaseHookOptions\n\n const queryKey = getKey(variables)\n\n const result = useRQHook(\n {\n ...mergedOptions,\n enabled:\n typeof enabled === 'function'\n ? enabled(client.getQueryData(queryKey), variables)\n : enabled,\n queryKey,\n },\n client\n )\n\n return Object.assign(result, {\n queryKey: queryKey,\n variables,\n setData: (updater: Updater<any, any>, setDataOptions?: SetDataOptions) =>\n client.setQueryData(queryKey, updater, setDataOptions),\n })\n }\n\n return Object.assign(\n withMiddlewares(useGeneratedQuery, defaultOptions, 'queries'),\n {\n getPrimaryKey,\n getKey,\n queryFn: defaultOptions.queryFn,\n queryKeyHashFn: defaultOptions.queryKeyHashFn,\n getFetchOptions,\n }\n )\n}\n"],"names":["createBaseQuery","defaultOptions","useRQHook","overrideOptions","primaryKey","process","env","NODE_ENV","useDefaultOptions","Error","getPrimaryKey","getKey","variables","getQueryKey","getFetchOptions","queryKey","queryFn","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","useGeneratedQuery","options","queryClient","client","useCompatibeQueryClient","enabled","mergedOptions","result","getQueryData","Object","assign","setData","updater","setDataOptions","setQueryData","withMiddlewares"],"mappings":";;AA2BO,SAASA,eAAT,CACLC,cADK,EAELC,SAFK,EAGLC,eAHK,EAIA;EACL,MAAM;AAAEC,IAAAA,UAAAA;AAAF,GAAA,GAAiBH,cAAvB,CAAA;;AAEA,EAAA,IAAII,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC;IACA,IAAIN,cAAc,CAACO,iBAAnB,EAAsC;AACpC,MAAA,MAAM,IAAIC,KAAJ,CACJ,oEADI,CAAN,CAAA;AAGD,KAAA;AACF,GAAA;;EAED,MAAMC,aAAa,GAAG,MAAMN,UAA5B,CAAA;;EAEA,MAAMO,MAAM,GAAIC,SAAD,IAAqBC,WAAW,CAACT,UAAD,EAAaQ,SAAb,CAA/C,CAAA;;EAEA,MAAME,eAAe,GAAIF,SAAD,IAAoB;IAC1C,OAAO;AACLG,MAAAA,QAAQ,EAAEJ,MAAM,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ApB,EAAoC,SAApC,CADV,EAEL;IACES,aADF;IAEEC,MAFF;IAGEK,OAAO,EAAEf,cAAc,CAACe,OAH1B;IAIEC,cAAc,EAAEhB,cAAc,CAACgB,cAJjC;AAKEH,IAAAA,eAAAA;AALF,GAFK,CAAP,CAAA;AAUD;;;;"}
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { AdditionalCreateOptions,
|
|
3
|
-
export interface CreateImmutableQueryOptions<TFnData, TVariables = any,
|
|
1
|
+
import type { UseQueryOptions } from '@tanstack/react-query';
|
|
2
|
+
import type { AdditionalCreateOptions, DefaultError, ImmutableQueryHook, Middleware, inferQueryKey } from './types';
|
|
3
|
+
export interface CreateImmutableQueryOptions<TFnData = unknown, TVariables = any, TError = DefaultError> extends Omit<UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>, 'queryKey' | 'queryFn' | 'enabled' | 'select' | 'refetchInterval' | 'refetchIntervalInBackground' | 'refetchOnMount' | 'refetchOnReconnect' | 'refetchOnWindowFocus' | 'staleTime' | 'gcTime' | 'cacheTime'>, Omit<AdditionalCreateOptions<TFnData, TVariables>, 'enabled'> {
|
|
4
|
+
use?: Middleware<ImmutableQueryHook<TFnData, TVariables, TError>>[];
|
|
4
5
|
}
|
|
5
|
-
export declare function createImmutableQuery<TFnData, TVariables = any,
|
|
6
|
-
useDefaultOptions: () => Omit<ImmutableQueryHookOptions<TFnData, Error, TFnData, TVariables>, 'select'> & {
|
|
7
|
-
variables: TVariables;
|
|
8
|
-
};
|
|
9
|
-
}, queryClient?: CompatibleWithV4<QueryClient, void>): ImmutableQueryHook<TFnData, TVariables, Error, TVariables | void>;
|
|
10
|
-
export declare function createImmutableQuery<TFnData, TVariables = any, Error = unknown>(options: CreateImmutableQueryOptions<TFnData, TVariables, Error> & {
|
|
11
|
-
useDefaultOptions: () => Omit<ImmutableQueryHookOptions<TFnData, Error, TFnData, TVariables>, 'select' | 'variables'>;
|
|
12
|
-
}, queryClient?: CompatibleWithV4<QueryClient, void>): ImmutableQueryHook<TFnData, TVariables, Error, TVariables>;
|
|
13
|
-
export declare function createImmutableQuery<TFnData, TVariables = any, Error = unknown>(options: CreateImmutableQueryOptions<TFnData, TVariables, Error>, queryClient?: CompatibleWithV4<QueryClient, void>): ImmutableQueryHook<TFnData, TVariables, Error, TVariables>;
|
|
6
|
+
export declare function createImmutableQuery<TFnData, TVariables = any, TError = DefaultError>(options: CreateImmutableQueryOptions<TFnData, TVariables, TError>): ImmutableQueryHook<TFnData, TVariables, TError>;
|