In my react native code, I'm loading a list of products from firebase firestore, from the products collection, when the app starts. Every product contains a user id. I'm trying to get user information from the users collection for every product.
In other words, I'm trying to build a new array that contains products' information however I want to replace the user id document with user information object.
what is the best way to do that ?
const GetProductsByDate = () => {
let products_list = []
const userRef = firestore().collection('users')
const productsRef = firestore()
.collection('products')
.orderBy('date_listed', 'desc')
.onSnapshot(querySnapshot => {
products_list = []
querySnapshot.forEach(async documentSnapshot => {
products_list.push({
...documentSnapshot.data(),
seller : awaituserRef.doc(documentSnapshot.data().seller.id).get().data(),
productId: documentSnapshot.id
})
})
setProducts(products_list)
})
return() => {
userRef
productsRef
}
}