@tanstack/react-query 4.42.2 → 4.44.0
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/build/lib/__tests__/mutationOptions.test.d.ts +2 -0
- package/build/lib/__tests__/mutationOptions.test.d.ts.map +1 -0
- package/build/lib/__tests__/mutationOptions.types.test.d.ts +2 -0
- package/build/lib/__tests__/mutationOptions.types.test.d.ts.map +1 -0
- package/build/lib/__tests__/usePrefetchInfiniteQuery.types.test.d.ts +2 -0
- package/build/lib/__tests__/usePrefetchInfiniteQuery.types.test.d.ts.map +1 -0
- package/build/lib/__tests__/usePrefetchQuery.types.test.d.ts +2 -0
- package/build/lib/__tests__/usePrefetchQuery.types.test.d.ts.map +1 -0
- package/build/lib/index.d.ts +3 -0
- package/build/lib/index.d.ts.map +1 -1
- package/build/lib/index.esm.js +3 -0
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.js +6 -0
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +3 -0
- package/build/lib/index.mjs.map +1 -1
- package/build/lib/mutationOptions.d.ts +5 -0
- package/build/lib/mutationOptions.d.ts.map +1 -0
- package/build/lib/mutationOptions.esm.js +6 -0
- package/build/lib/mutationOptions.esm.js.map +1 -0
- package/build/lib/mutationOptions.js +10 -0
- package/build/lib/mutationOptions.js.map +1 -0
- package/build/lib/mutationOptions.mjs +6 -0
- package/build/lib/mutationOptions.mjs.map +1 -0
- package/build/lib/usePrefetchInfiniteQuery.d.ts +3 -0
- package/build/lib/usePrefetchInfiniteQuery.d.ts.map +1 -0
- package/build/lib/usePrefetchInfiniteQuery.esm.js +12 -0
- package/build/lib/usePrefetchInfiniteQuery.esm.js.map +1 -0
- package/build/lib/usePrefetchInfiniteQuery.js +16 -0
- package/build/lib/usePrefetchInfiniteQuery.js.map +1 -0
- package/build/lib/usePrefetchInfiniteQuery.mjs +12 -0
- package/build/lib/usePrefetchInfiniteQuery.mjs.map +1 -0
- package/build/lib/usePrefetchQuery.d.ts +3 -0
- package/build/lib/usePrefetchQuery.d.ts.map +1 -0
- package/build/lib/usePrefetchQuery.esm.js +12 -0
- package/build/lib/usePrefetchQuery.esm.js.map +1 -0
- package/build/lib/usePrefetchQuery.js +16 -0
- package/build/lib/usePrefetchQuery.js.map +1 -0
- package/build/lib/usePrefetchQuery.mjs +12 -0
- package/build/lib/usePrefetchQuery.mjs.map +1 -0
- package/build/umd/index.development.js +23 -0
- 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 -2
- package/src/__tests__/mutationOptions.test.tsx +140 -0
- package/src/__tests__/mutationOptions.types.test.tsx +438 -0
- package/src/__tests__/usePrefetchInfiniteQuery.types.test.tsx +45 -0
- package/src/__tests__/usePrefetchQuery.types.test.tsx +56 -0
- package/src/index.ts +3 -0
- package/src/mutationOptions.ts +34 -0
- package/src/usePrefetchInfiniteQuery.ts +23 -0
- package/src/usePrefetchQuery.ts +23 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { OmitKeyof, WithRequired } from '@tanstack/query-core'
|
|
2
|
+
import type { UseMutationOptions } from './types'
|
|
3
|
+
|
|
4
|
+
export function mutationOptions<
|
|
5
|
+
TData = unknown,
|
|
6
|
+
TError = unknown,
|
|
7
|
+
TVariables = void,
|
|
8
|
+
TContext = unknown,
|
|
9
|
+
>(
|
|
10
|
+
options: WithRequired<
|
|
11
|
+
UseMutationOptions<TData, TError, TVariables, TContext>,
|
|
12
|
+
'mutationKey'
|
|
13
|
+
>,
|
|
14
|
+
): WithRequired<
|
|
15
|
+
UseMutationOptions<TData, TError, TVariables, TContext>,
|
|
16
|
+
'mutationKey'
|
|
17
|
+
>
|
|
18
|
+
export function mutationOptions<
|
|
19
|
+
TData = unknown,
|
|
20
|
+
TError = unknown,
|
|
21
|
+
TVariables = void,
|
|
22
|
+
TContext = unknown,
|
|
23
|
+
>(
|
|
24
|
+
options: OmitKeyof<
|
|
25
|
+
UseMutationOptions<TData, TError, TVariables, TContext>,
|
|
26
|
+
'mutationKey'
|
|
27
|
+
>,
|
|
28
|
+
): OmitKeyof<
|
|
29
|
+
UseMutationOptions<TData, TError, TVariables, TContext>,
|
|
30
|
+
'mutationKey'
|
|
31
|
+
>
|
|
32
|
+
export function mutationOptions(options: unknown) {
|
|
33
|
+
return options
|
|
34
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useQueryClient } from './QueryClientProvider'
|
|
2
|
+
import type {
|
|
3
|
+
FetchInfiniteQueryOptions,
|
|
4
|
+
QueryKey,
|
|
5
|
+
WithRequired,
|
|
6
|
+
} from '@tanstack/query-core'
|
|
7
|
+
|
|
8
|
+
export function usePrefetchInfiniteQuery<
|
|
9
|
+
TQueryFnData = unknown,
|
|
10
|
+
TError = unknown,
|
|
11
|
+
TData = TQueryFnData,
|
|
12
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
13
|
+
>(
|
|
14
|
+
options: WithRequired<
|
|
15
|
+
FetchInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
16
|
+
'queryKey'
|
|
17
|
+
>,
|
|
18
|
+
) {
|
|
19
|
+
const client = useQueryClient()
|
|
20
|
+
if (!client.getQueryState(options.queryKey)) {
|
|
21
|
+
client.prefetchInfiniteQuery(options)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useQueryClient } from './QueryClientProvider'
|
|
2
|
+
import type {
|
|
3
|
+
FetchQueryOptions,
|
|
4
|
+
QueryKey,
|
|
5
|
+
WithRequired,
|
|
6
|
+
} from '@tanstack/query-core'
|
|
7
|
+
|
|
8
|
+
export function usePrefetchQuery<
|
|
9
|
+
TQueryFnData = unknown,
|
|
10
|
+
TError = unknown,
|
|
11
|
+
TData = TQueryFnData,
|
|
12
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
13
|
+
>(
|
|
14
|
+
options: WithRequired<
|
|
15
|
+
FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
16
|
+
'queryKey'
|
|
17
|
+
>,
|
|
18
|
+
) {
|
|
19
|
+
const client = useQueryClient()
|
|
20
|
+
if (!client.getQueryState(options.queryKey)) {
|
|
21
|
+
client.prefetchQuery(options)
|
|
22
|
+
}
|
|
23
|
+
}
|