Getting the users collection from firestore:
useEffect(() => {
if (currentUser) {
const unsubscribe = db
.collection("users")
.doc(uid)
.onSnapshot((snapshot) => {
const arr = [];
arr.push({
...snapshot.data(),
});
setUsers(arr);
console.log(JSON.stringify(arr));
});
return () => {
unsubscribe();
};
}
}, [currentUser]);
This is what is shows where I console.log(JSON.stringify(arr));
[
{
1: { others: "books", items: { Item1: true, Item2: true } },
2: {
items: { Item3: true, Item2: true },
others: "books",
},
displayName: Inigi,
address: "US",
},
];
I am new to react so this is quite confusing to me. How do I retrieve and display those 1 and 2?
I tried this but it does not work and I keep on getting an error:"
TypeError: _user$.items.map is not a function
{user["1"]?.items.map((index) => (
<li>{index.Item1}</li>
))}
You can use {user["1"]?.others}