感谢您阅读本文,
我正在尝试引用集合companies/{currentCompany/users/{currentUserUID}中Firebase FireStore中名为userRole的字段
使用用户集合中的公司代码(当我使用console.log时,这一切都有效)
但是,我在第二个useEffect中收到未定义的错误
即使我在请求中添加硬拷贝的数据/代码/值,我仍然会得到相同的错误
const [currentUserUID, setCurrentUserUID] = useState(null)
const [currentUserCompanyCode, setCurrentUserCompanyCode] = useState(null)
const [currentUserCompanyRole, setCurrentUserCompanyCodeRole] = useState(null)
useEffect(() => {
if (currentUserUID != null) {
const docRefUser = doc(projectDb, "users", currentUserUID);
getDoc (docRefUser).then((doc) => {
setCurrentUserCompanyCode(doc.data().companyCode)
})
}
}, [currentUserUID]);
useEffect(() => {
if (currentUserCompanyCode != null && currentUserUID != null) {
const docRefCompany = doc(projectDb, "companies", currentUserCompanyCode, "users", currentUserUID);
getDoc (docRefCompany).then((doc) => {
setCurrentUserCompanyCodeRole(doc.data().userRole)
})
}
}, [currentUserCompanyCode, currentUserUID]);
console.log(currentUserCompanyCode)
console.log(currentUserCompanyRole)
1条答案
按热度按时间bq3bfh9z1#
我已经在Firebase Firestore中重新创建了字段/文档/集合,并修复了该问题。