please can you help me to write this request in a new firebase notation please
useEffect(() => {
let unsubscribe;
if(postId){
unsubscribe =db
.collection("posts")
.doc(postId)
.colection("comments")
.onSnapshot((snapshot)=>{
setcomments(snapshot.doc.map((doc)=>doc.data()))
})
}
}, []);
best regards
im trying to write it but i dont how can i use "db.doc"
im writing somthing like that
useEffect(() => {
onSnapshot(
collection(db, "posts", "comments"),(snapshot) =>
setcomments(
snapshot.docs.map((doc) =>
post: doc.data())
)
);
}, []);
but it’s not work
3
Answers
thanks a lot my friend, but now, in my console, i have this error " Cannot access 'collection' before initialization" i show you my modification
The following should do the trick:
More details on how to declare sub-collections with the JS SDK v9 in this article.
im fixed the probléme like that:
but now i have this error: "Uncaught TypeError: Cannot read properties of undefined (reading ‘map’) at Array."
please can you help me?