File tree Expand file tree Collapse file tree 2 files changed +56
-1
lines changed Expand file tree Collapse file tree 2 files changed +56
-1
lines changed Original file line number Diff line number Diff line change 77 getSimpleFetcherWithReturnData ,
88} from './test-utils'
99import { useQueries } from '../useQueries'
10+ import { useQueryClient } from '../useQueryClient'
11+ import { QueryClient } from '../queryClient'
1012
1113jest . mock ( '../useQueryClient' )
1214
@@ -190,4 +192,43 @@ describe('useQueries', () => {
190192 } ,
191193 ] )
192194 } )
195+
196+ test ( 'should use queryClient provided via options' , async ( ) => {
197+ const queryClient = new QueryClient ( )
198+ const queries = [
199+ {
200+ queryKey : [ 'key41' ] ,
201+ queryFn : simpleFetcher ,
202+ } ,
203+ {
204+ queryKey : [ 'key42' ] ,
205+ queryFn : simpleFetcher ,
206+ } ,
207+ ]
208+
209+ useQueries ( { queries, queryClient } )
210+ await flushPromises ( )
211+
212+ expect ( useQueryClient ) . toHaveBeenCalledTimes ( 0 )
213+ } )
214+
215+ test ( 'should use queryClient provided via query options' , async ( ) => {
216+ const queryClient = new QueryClient ( )
217+ const queries = [
218+ {
219+ queryKey : [ 'key41' ] ,
220+ queryFn : simpleFetcher ,
221+ queryClient,
222+ } ,
223+ {
224+ queryKey : [ 'key42' ] ,
225+ queryFn : simpleFetcher ,
226+ } ,
227+ ]
228+
229+ useQueries ( { queries } )
230+ await flushPromises ( )
231+
232+ expect ( useQueryClient ) . toHaveBeenCalledTimes ( 0 )
233+ } )
193234} )
Original file line number Diff line number Diff line change @@ -135,8 +135,10 @@ type UseQueriesOptionsArg<T extends any[]> = readonly [...UseQueriesOptions<T>]
135135
136136export function useQueries < T extends any [ ] > ( {
137137 queries,
138+ queryClient : queryClientInjected ,
138139} : {
139140 queries : Ref < UseQueriesOptionsArg < T > > | UseQueriesOptionsArg < T >
141+ queryClient ?: QueryClient
140142} ) : Readonly < UseQueriesResults < T > > {
141143 const unreffedQueries = computed (
142144 ( ) => cloneDeepUnref ( queries ) as UseQueriesOptionsArg < T > ,
@@ -146,7 +148,19 @@ export function useQueries<T extends any[]>({
146148 const optionsQueryClient = unreffedQueries . value [ 0 ] ?. queryClient as
147149 | QueryClient
148150 | undefined
149- const queryClient = optionsQueryClient ?? useQueryClient ( queryClientKey )
151+ const queryClient =
152+ queryClientInjected ?? optionsQueryClient ?? useQueryClient ( queryClientKey )
153+ if (
154+ process . env . NODE_ENV !== 'production' &&
155+ ( queryClientKey || optionsQueryClient )
156+ ) {
157+ queryClient
158+ . getLogger ( )
159+ . error (
160+ `Providing queryClient to individual queries in useQueries has been deprecated and will be removed in the next major version. You can still pass queryClient as an option directly to useQueries hook.` ,
161+ )
162+ }
163+
150164 const defaultedQueries = computed ( ( ) =>
151165 unreffedQueries . value . map ( ( options ) => {
152166 const defaulted = queryClient . defaultQueryOptions ( options )
You can’t perform that action at this time.
0 commit comments