I'm trying to access what's returned by secondSnapshot.data(), but am having an issue, as described by the comments below. I tried to create an async function, but to no avail. Any idea what's going wrong? Please view the 2 comments.
useEffect(() => {
firestore.collection(`comments`).onSnapshot((snapshot) => {
const posts = snapshot.docs
.map((doc) => {
const address = doc.data().comments?.map((comment) => {
comment.get().then((secondSnapshot) => {
console.log("snapshot", secondSnapshot.data());
#I SEE WHAT I EXPECT TO SEE
return secondSnapshot.data();
});
});
console.log(address) #THIS RETURNS UNDEFINED FOR SOME REASON??
return {
username: doc.data().username,
date: doc.data().date.seconds,
text: doc.data().text,
votes: doc.data().votes,
comments: [],
};
});
props.setComments(posts);
});
}, [location]);