I am currently trying to learn ReactJS. For my projects I am getting data from firestore and then want to display on the screen.
Data in Firestore is stored as :
category: "Lemon"
currentUser:
createdAt: October 21, 2020 at 2:52:25 PM UTC+5:30
displayName: null
email: "[email protected]"
id: "123"
dish: "vs"
image: "imageurl"
price: "8"
To retrieve this data I am using:
useEffect(() => {
let m = [];
var docRef = firestore.collection("Dish");
docRef.get().then(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
m.push({
id: doc.id,
category: doc.data().category,
});
});
Setmida(m);
Setmid(false);
if (mid === false) {
let big = [];
mida.map((f) => {
let items = [];
var docRef = firestore
.collection("Dish")
.where("category", "==", "Lemon");
docRef.get().then(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
items.push({
dish: doc.data().dish,
});
});
});
big.push({
id: f.id,
category: f.category,
items,
});
});
Setdata(big);
Setload(false);
}
});
}, [mid]);
Category and Id are well. But the problem arises when I try to access items. So far I have tried to access it by index:
data[0].items[0]
But it just shows undefined in console.
When trying to use map on the data[0].items. It just doesn't do anything, no errors, it just won't print any details.
data[0].items.[0]? Should it bedata[0].items[0]? Also, what doesdata[0].itemsgive you?