invertase / react-query-firebase

React Query hooks for managing asynchronous operations with Firebase. Supports Authentication, Analytics, Firestore & Realtime Database.
https://react-query-firebase.invertase.dev
Apache License 2.0
389 stars 68 forks source link

Querying firestore documents with subscribe never fetches #73

Open CalvinMoylan opened 1 year ago

CalvinMoylan commented 1 year ago

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,
});

image

it does work with useFirestoreQuery

"@react-query-firebase/firestore": "^1.0.0-dev.7" "firebase": "^9.11.0" "react-query": "^3.39.2"

PatrikTheDev commented 1 year ago

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

bgalek commented 1 year ago

any chances for a merge? :)

KarikoGoat commented 1 year ago

I am also experiencing the same problem, so it would be very appriciated if it got fixed

jagthedrummer commented 1 year ago

Would also appreciate a merge and release.

rizooooo commented 1 year ago

While waiting for this fix, I created a temporary custom hook. :)

Screenshot 2023-02-03 at 1 38 18 PM Screenshot 2023-02-03 at 1 37 57 PM
martsim6 commented 1 year ago

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!

Banfanci commented 1 year ago

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
}
kabtamu-degifie commented 7 months ago

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