5
5
reactive ,
6
6
readonly ,
7
7
watch ,
8
- unref ,
9
8
Ref ,
10
9
isRef ,
11
10
isReactive ,
@@ -18,6 +17,7 @@ import type {
18
17
19
18
import { useQueryClient } from "./useQueryClient" ;
20
19
import { UseQueryOptions } from "./useQuery" ;
20
+ import { cloneDeepUnref } from "./utils" ;
21
21
22
22
// Avoid TS depth-limit error in case of large array literal
23
23
type MAXIMUM_DEPTH = 20 ;
@@ -138,28 +138,28 @@ type UseQueriesOptionsArg<T extends any[]> = readonly [...UseQueriesOptions<T>];
138
138
export function useQueries < T extends any [ ] > (
139
139
queries : Ref < UseQueriesOptionsArg < T > > | UseQueriesOptionsArg < T >
140
140
) : Readonly < UseQueriesResults < T > > {
141
- const queryClientKey = ( unref ( queries ) as UseQueriesOptionsArg < T > ) [ 0 ]
142
- ?. queryClientKey ;
141
+ const unreffedQueries = cloneDeepUnref ( queries ) as UseQueriesOptionsArg < T > ;
142
+
143
+ const queryClientKey = unreffedQueries [ 0 ] ?. queryClientKey ;
143
144
const queryClient = useQueryClient ( queryClientKey ) ;
144
- const defaultedQueries = ( unref ( queries ) as UseQueriesOptionsArg < T > ) . map (
145
- ( options ) => {
146
- return queryClient . defaultQueryObserverOptions ( options ) ;
147
- }
148
- ) ;
145
+ const defaultedQueries = unreffedQueries . map ( ( options ) => {
146
+ return queryClient . defaultQueryObserverOptions ( options ) ;
147
+ } ) ;
149
148
150
149
const observer = new QueriesObserver ( queryClient , defaultedQueries ) ;
151
150
const state = reactive ( observer . getCurrentResult ( ) ) ;
151
+
152
152
const unsubscribe = observer . subscribe ( ( result ) => {
153
153
state . splice ( 0 , state . length , ...result ) ;
154
154
} ) ;
155
155
156
156
if ( isRef ( queries ) || isReactive ( queries ) ) {
157
157
watch ( queries , ( ) => {
158
- const defaulted = ( unref ( queries ) as UseQueriesOptionsArg < T > ) . map (
159
- ( options ) => {
160
- return queryClient . defaultQueryObserverOptions ( options ) ;
161
- }
162
- ) ;
158
+ const defaulted = (
159
+ cloneDeepUnref ( queries ) as UseQueriesOptionsArg < T >
160
+ ) . map ( ( options ) => {
161
+ return queryClient . defaultQueryObserverOptions ( options ) ;
162
+ } ) ;
163
163
observer . setQueries ( defaulted ) ;
164
164
} ) ;
165
165
}
0 commit comments