I am arrays of objects from multiple firestore collections and storing them all in an object. I want to render the individual objects in the arrays is the object. This is how I fetch my data:
const categories = {
Pakoras: [],
Vegitarisches: [],
"Biryani Gerichte": [],
Hähnchengerichte: [],
"Indische Beilagen": [],
Lammgerichte: [],
"Ben & Jerrys": [],
Getränke: [],
Pizza: [],
Kindermenüs: [],
Spaghetti: [],
Tortellini: [],
Gnochi: [],
Maccheroni: [],
Tagliatelle: [],
"Überbackene Nudeln": [],
Salate: [],
Fleischgerichte: [],
"Schnitzel & Fleischgerichte": [],
Risotto: [],
"Überbackenes-Gemüse-Kartoffeln": [],
"Chinesische-Gerichte-Gebratene-Nudeln-Reis": [],
}
const [foods, setFoods] = useState(categories)
useEffect(() => {
fetch()
}, [])
function fetch(){
console.log("Fetching")
Object.keys(categories).forEach(category => {
fire.firestore().collection(category).get()
.then(snapshot => {
var food = []
snapshot.forEach(doc => {
food.push(doc.data())
//console.log(doc.data())
})
categories[category] = food;
}).catch(error => {
console.log(error)
})
})
//console.log(foods)
}
A doc.data() object looks something like this:
var example = {
title: "example",
price: 10,
desc: "none"
}
The objects are in an array under the respective category. How do I render this? I want to loop through everything and render it like this:
Category1:
- title - price - desc
- title - price - desc
Category2:
- title - price - desc
- title - price - desc