Load data only once with useFirestoreConnect

332 Views Asked by At

I am using useFirestoreConnect hook to get data from collections and need data from collection only once.

But on official documentation here, There is no mention of turning off listeners. due to which my daily free quota exceeds sometime.

Is it possible to load data only once with useFirestoreConnect?

1

There are 1 best solutions below

0
On

Option 1: Unmount component to stop the listener.

useFirestoreConnect is a React hook that manages attaching and detaching listeners for you as the component mounts and unmounts.

https://react-redux-firebase.com/docs/firestore

Option 2: Make the query with useFirestore()

const firestore = useFirestore();
var docRef = firestore.collection("cities").doc("SF");

docRef.get().then((doc) => {
     if (doc.exists) {
     console.log("Document data:", doc.data());
     } else {
          // doc.data() will be undefined in this case
          console.log("No such document!");
     }
}).catch((error) => {
    console.log("Error getting document:", error);
});

http://react-redux-firebase.com/docs/api/useFirestore.html

https://firebase.google.com/docs/firestore/query-data/get-data#get_a_document