react-query-firebase
react-query-firebase copied to clipboard
Querying firestore documents with subscribe never fetches
just never finishes fetching. setting subscribe to false fetches instantly
const ref = doc(firestore, "games", id);
const { data, isLoading } = useFirestoreDocumentData(["games", id], ref, {
subscribe: true,
});
it does work with useFirestoreQuery
"@react-query-firebase/firestore": "^1.0.0-dev.7"
"firebase": "^9.11.0"
"react-query": "^3.39.2"
Also noticed this, happens with RTDB as well. It does return once an update to the DB occurs though. I'm guessing some interaction with React Query regarding the updates isn't right
any chances for a merge? :)
I am also experiencing the same problem, so it would be very appriciated if it got fixed
Would also appreciate a merge and release.
While waiting for this fix, I created a temporary custom hook. :)


would be nice to have this fix merged. I rewrote whole app to use-query-firebase and now due this I have to rewrite it back or use custom logic when need to subscribe to document changes...
Please, make it work. Thanks!
For getting multiple docs like useFirestoreQuery
import { DocumentData, getDocs, onSnapshot, Query } from "firebase/firestore"
import { useEffect } from "react"
import { useQuery } from "react-query"
interface IProps {
keyName: Partial<string[]>
query: Query<DocumentData>
subscribe?: boolean
}
export const useCustomFireStoreQuery = ({ keyName, query, subscribe = false }: IProps) => {
const getQuery = useQuery(keyName, async () => {
const snapshot = await getDocs(query)
return snapshot
})
useEffect(() => {
if (subscribe) {
const unsub = onSnapshot(query, (doc) => {
getQuery.refetch()
})
return () => unsub()
}
}, [subscribe, query])
return getQuery
}
The issues regarding infinite loading and disabled functionality associated with the useFirestoreDocumentData hook have been resolved. Therefore, we can now utilize it with Next.js versions 13 or 14. https://github.com/invertase/react-query-firebase/pull/97