onSnapshot
v8
unsub = firestore
.collection("chats")
.where("roomid", "==", roomid)
.orderBy("timestamp", "desc")
.onSnapshot((snapshot) => {
let docs = [];
snapshot.docs.forEach((each) => {
docs.push({ ...each.data(), id: each.id });
});
setChats(docs);
setLoading(false);
});
return () => unsub();
v9
unsub = onSnapshot(query(collection(firestore,
"projects"),where("completed", "==", true)),
(doc) => {
let data = [];
doc.forEach((each) => {
data.push({ ...each.data(), uid: each.id });
});
setProjects([...data]);
setLoading(false);
data = [];
});
insert
v8
const ref = firestore.collection("chats");
await ref.doc().set(newDoc);
v9
await addDoc(collection(firestore, "projects"), projectDetails)
update
v8
const query = firestore.collection("Lopn").doc(user.uid);
query.update(doc);
v9
const ref = doc(firestore, "projects", pid);
await updateDoc(ref, data);
Top comments (0)