【发布时间】:2023-01-27 00:27:15
【问题描述】:
每次我运行以下代码时,React 似乎都在继续,而不是像我在 setCurrentDevice 中要求的那样填充 CurrentDevice。当在最后一行询问时,它只是在日志中抛出一个 undefined 。它似乎确实记录了正确的设备详细信息,正如我在第一个 console.log 运行时看到的那样。在继续之前如何使反应填充状态 CurrentDevice?
const q = query(collection(db, 'DeviceDetails'), where('serialNo', '==', SerialNo))
const querySnapshot = await getDocs(q)
querySnapshot.forEach((doc) => {
// doc.data() is never undefined for query doc snapshots
setCurrentDevice(doc.data());
console.log(doc.data());
})
console.log(currentDevice);
【问题讨论】:
标签: reactjs firebase google-cloud-firestore