I have these Collections:
- User(Uid = document) with name and image,
- Post(Uid Post = doucment) includes body, image and Uid (Uid user)
I am using nested loops to have a simple object (I do not use 2 arrays)
firebase.firestore().collection("Post").get()
.then(querySnapshot => {
querySnapshot.forEach(documentSnapshot => {
this.setState({
dataPost: this.state.dataPost.concat({
...documentSnapshot.data(),
key: documentSnapshot.id,
name: this.getUserbyUid(documentSnapshot.data().uid) <- get Name user as soon as I get the uid from the Post collection
}),
})
});
});
getUserbyUid = (Uid) => {
firebase.firestore().collection('user').doc(Uid).get()
.then(documentSnapshot => {
return documentSnapshot.data().name
})}
I get an error name: Undefinded
This is the way I think, I know there are many better ways please help me tks
Post
User
Object {
"body": "hfdbdb"
"date": 1614903953253,
"image": “"https://firebasestorage.googleapis.com/v0/t.....-44¢5-b091-7af310de36d1",
"key": "IX9KKfcOONSyquUtossTd",
"name": undefined,
"uid": "Chc1P3zcWMguc2d2ppKSRrpQx752",
},

