1- import { type UseQueryOptions , useQuery } from "@tanstack/react-query" ;
1+ import { InitialDataFunction , type UseQueryOptions , useQuery } from "@tanstack/react-query" ;
22import type { FirebaseError } from "firebase/app" ;
33import {
44 type CallerSdkType ,
@@ -20,20 +20,25 @@ export type useDataConnectQueryOptions<
2020> = PartialBy < Omit < UseQueryOptions < TData , TError > , "queryFn" > , "queryKey" > ;
2121
2222export 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
2630) : 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 ;
3134 const { ref } = dataConnectResult ;
3235
3336 if ( "ref" in refOrResult ) {
3437 initialData = {
3538 ...refOrResult . data ,
3639 } ;
40+ } else {
41+ initialData = options ?. initialData ;
3742 }
3843
3944 // @ts -expect-error function is hidden under `DataConnect`.
0 commit comments