I'm struggling to correctly manage the synchronization, asynchronization, and promises related to querying Firestore. Let me simplify my scenario for you. I have different categories of items and I want to display all the categories along with their respective items in a specific way. This is done through the 'Display' function, which takes an array of items belonging to a category as a parameter.
categories=["ct1","ct2"]
....
async function fetchItems(category){
let items=[]
const snapshot = await db.collection("items").where("category","array-contains",category).get()
snapshot.forEach((doc=>items.push(doc.data())))
return items;
}
....
LOOP THROUGH CATEGORIES
Display(fetchItems(category))
The issue arises when trying to handle Promises. The 'fetchItems' function returns a promise instead of an array. How can I successfully pass the data retrieved from Firestore to the 'display' function?