@@ -3,6 +3,7 @@ import type {
3
3
DefaultError ,
4
4
FetchInfiniteQueryOptions ,
5
5
FetchQueryOptions ,
6
+ QueryClient ,
6
7
QueryKey ,
7
8
} from '@tanstack/query-core'
8
9
@@ -11,11 +12,14 @@ export function usePrefetchQuery<
11
12
TError = DefaultError ,
12
13
TData = TQueryFnData ,
13
14
TQueryKey extends QueryKey = QueryKey ,
14
- > ( options : FetchQueryOptions < TQueryFnData , TError , TData , TQueryKey > ) {
15
- const queryClient = useQueryClient ( )
15
+ > (
16
+ options : FetchQueryOptions < TQueryFnData , TError , TData , TQueryKey > ,
17
+ queryClient ?: QueryClient ,
18
+ ) {
19
+ const client = useQueryClient ( queryClient )
16
20
17
- if ( ! queryClient . getQueryState ( options . queryKey ) ) {
18
- queryClient . prefetchQuery ( options )
21
+ if ( ! client . getQueryState ( options . queryKey ) ) {
22
+ client . prefetchQuery ( options )
19
23
}
20
24
}
21
25
@@ -33,10 +37,11 @@ export function usePrefetchInfiniteQuery<
33
37
TQueryKey ,
34
38
TPageParam
35
39
> ,
40
+ queryClient ?: QueryClient ,
36
41
) {
37
- const queryClient = useQueryClient ( )
42
+ const client = useQueryClient ( queryClient )
38
43
39
- if ( ! queryClient . getQueryState ( options . queryKey ) ) {
40
- queryClient . prefetchInfiniteQuery ( options )
44
+ if ( ! client . getQueryState ( options . queryKey ) ) {
45
+ client . prefetchInfiniteQuery ( options )
41
46
}
42
47
}
0 commit comments