I have the following code that log to console all my document data. The problem is that I only receive updates as the function runs. I like to know how to setup a listener that log to console when data changes
const db = firebase.firestore();
const todoRef = db.collection("todo");
const list = (date) => {
console.log(date);
return todoRef
.where("owner", "==", firebase.auth().currentUser.uid)
.where("date", "==", date)
.get()
.then((querySnapshot) => {
const data = [];
querySnapshot.forEach((doc) => {
const d = {
id: doc.id,
...doc.data(),
};
data.push(d);
});
return data;
});
};
console.log("database stuff", list("2021 - 07 - 12"));