【发布时间】:2021-08-29 05:36:30
【问题描述】:
从 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]);
这就是我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",
},
];
我是新手,所以这让我很困惑。如何检索和显示那些1 和2?
我试过了,但它不起作用,我不断收到错误:"
TypeError: _user$.items.map 不是函数
{user["1"]?.items.map((index) => (
<li>{index.Item1}</li>
))}
【问题讨论】:
标签: javascript reactjs firebase google-cloud-firestore