1
- import { type UseQueryOptions , useQuery } from "@tanstack/react-query" ;
1
+ import { InitialDataFunction , type UseQueryOptions , useQuery } from "@tanstack/react-query" ;
2
2
import type { FirebaseError } from "firebase/app" ;
3
3
import {
4
4
type CallerSdkType ,
@@ -20,20 +20,25 @@ export type useDataConnectQueryOptions<
20
20
> = PartialBy < Omit < UseQueryOptions < TData , TError > , "queryFn" > , "queryKey" > ;
21
21
22
22
export function useDataConnectQuery < Data = unknown , Variables = unknown > (
23
- refOrResult : QueryRef < Data , Variables > | QueryResult < Data , Variables > ,
24
- options ?: useDataConnectQueryOptions < Data , FirebaseError > ,
25
- _callerSdkType : CallerSdkType = CallerSdkTypeEnum . TanstackReactCore ,
23
+ refOrResult : QueryRef < Data , Variables >
24
+ | QueryResult < Data , Variables > ,
25
+ options ?: useDataConnectQueryOptions <
26
+ Data ,
27
+ FirebaseError
28
+ > ,
29
+ _callerSdkType : CallerSdkType = CallerSdkTypeEnum . TanstackReactCore
26
30
) : UseDataConnectQueryResult < Data , Variables > {
27
- const [ dataConnectResult , setDataConnectResult ] = useState <
28
- QueryResultRequiredRef < Data , Variables >
29
- > ( "ref" in refOrResult ? refOrResult : { ref : refOrResult } ) ;
30
- let initialData : Data | undefined ;
31
+ const [ dataConnectResult , setDataConnectResult ] = useState < QueryResultRequiredRef < Data , Variables > > ( 'ref' in refOrResult ? refOrResult : { ref : refOrResult } ) ;
32
+ // TODO(mtewani): in the future we should allow for users to pass in `QueryResult` objects into `initialData`.
33
+ let initialData : Data | InitialDataFunction < Data > | undefined ;
31
34
const { ref } = dataConnectResult ;
32
35
33
36
if ( "ref" in refOrResult ) {
34
37
initialData = {
35
38
...refOrResult . data ,
36
39
} ;
40
+ } else {
41
+ initialData = options ?. initialData ;
37
42
}
38
43
39
44
// @ts -expect-error function is hidden under `DataConnect`.
0 commit comments