I am having trouble subscribing to changes in Firebase's Firestore. I am developing my first React Native project with Firebase, therefore i am not really familiar with Firebase.
The Firebase connection is working: I can add and read data from the Firstore.
So far I have tried to replicate this issue: React useState and Firebase onSnapshot which did not work for me.
useEffect(() => {
const q = query(collection(db, "rooms"), where("active", "==", "true"));
const unsubscribe = onSnapshot(q, (querySnapshot) => {
setUser(querySnapshot);
});
console.log("User: " + user);
return () => {
unsubscribe();
};
}, []);
When I run it I get the following output User: undefined
I have also tried this approach:
const q = query(collection(db, "rooms"), where("active", "==", "true"));
const unsubscribe = onSnapshot(q, (querySnapshot) => {
querySnapshot.forEach((doc) => {
console.log(doc);
});
});
unsubscribe();
That's not working either.
Here you can see my Firestore: Firestore
Is there anything I am missing? Your help is really appreciated!