I am following along with a tutorial in which using Firestore to retrieve data from a collection. there two major things: retrieve DOCUMENT and COLLECTION that's nested inside that DOCUMENT. My code down below is based on FireStore web v8, and I want to convert it to web version 9. I found it very complicated !
useEffect(()=>{
if(roomId){
db.collection('rooms').doc(roomId).onSnapshot(snapshot => {
setRoomName(snapshot.data().name);
});
db.collection('rooms').doc(roomId).collection("messages").orderBy("timestamp","asc").onSnapshot(snapshot => {
setMessages(snapshot.docs.map(doc => doc.data()))
});
}
},[roomId])