Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Querying firestore documents with subscribe never fetches #73

Open
CalvinMoylan opened this issue Oct 19, 2022 · 8 comments · May be fixed by #77
Open

Querying firestore documents with subscribe never fetches #73

CalvinMoylan opened this issue Oct 19, 2022 · 8 comments · May be fixed by #77

Comments

@CalvinMoylan
Copy link

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
Copy link

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

@mbergal mbergal linked a pull request Nov 10, 2022 that will close this issue
@bgalek
Copy link

bgalek commented Dec 8, 2022

any chances for a merge? :)

@KarikoGoat
Copy link

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

@jagthedrummer
Copy link

Would also appreciate a merge and release.

@rizooooo
Copy link

rizooooo commented Feb 3, 2023

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
Copy link

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
Copy link

Banfanci commented Apr 25, 2023

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
Copy link

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.
#97

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants