Home > Enterprise >  useCollectionOnce infinite loading
useCollectionOnce infinite loading

Time:07-17

I'm using react-firebase-hooks to load data from firestore, and everything is working properly when I use useDocument or useCollection, but when I try to replace these methods with useDocumentOnce or useCollectionOnce I got an infinite loading.

useCollectionOnce:

const [data, isLoading, isError] = useCollectionOnce( //Infinite loading
   query(
     collection(
       getFirestore(),
       'examplePath'
    ),
     orderBy('test'),
     limit(2)
    ),
    {
       getOptions: {
          source: 'server'
       }
   }
 )

 useEffect(() => {
   console.debug(isLoading) // Output always true
 }, [isLoading])

useCollection:

 const [data, isLoading, isError] = useCollection( //Working Properly
   query(
     collection(
       getFirestore(),
       'examplePath'
    ),
     orderBy('test'),
     limit(2)
    ),
   }
 )

 useEffect(() => {
   console.debug(isLoading) // Output false after data is retrived
 }, [isLoading])

Same thing happen with useDocumentOnce.

NOTE If a hot reload is triggered, useCollectionOnce loads the data.

CodePudding user response:

React StrictMode causes the problem. I hope that this answer will help someone. For more information see https://github.com/CSFrequency/react-firebase-hooks/issues/256#issuecomment-1184750056.

  • Related