gpt4 book ai didi

React Firestore Useeffect error type error "undefined indexOf" when accessing user collection(访问用户集合时,Reaction FiRestore UseEffect错误类型错误“unfined indexOf”)

转载 作者:bug小助手 更新时间:2023-10-24 20:54:07 28 4
gpt4 key购买 nike



Getting a particular error on first render of useeffect that i am not sure how to get around. I believe it has to do with the async nature of the function but not sure. Project is a Reactjs, Firebase, Firestore Todo app that updates data based on user signed in.

在第一次渲染Use Effect时遇到一个特定的错误,我不确定如何解决。我认为这与该功能的异步性有关,但不确定。项目是一个Reactjs,Firebase,FiRestore Todo应用程序,根据用户登录更新数据。





useEffect( () => {
const getData = async () => {

const uid = await user.uid; //from context of user object
console.log(uid);

const q = await query(collection(db,'userData', uid, 'todos'));

const unsubscribe = onSnapshot(q, (querySnapshot) => {
let todosArr = [];
querySnapshot.forEach((doc) => {
todosArr.push({...doc.data(), id: doc.id})
});
setTodos(todosArr)
});
return () => unsubscribe();
}
getData();






}, [user.uid]);
```





This is the Error in the console :

path.ts:230 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'indexOf')
at ResourcePath.fromString (path.ts:230:1)
at collection (reference.ts:418:1)
at getData (TodoPage.js:63:1)
fromString @ path.ts:230
collection @ reference.ts:418
getData @ TodoPage.js:63
await in getData (async)
(anonymous) @ TodoPage.js:73


I tried making the uid data a state outside of the useeffect but still not working. Wondering how i can fix this error from within the useeffect. Thanks for your help!

更多回答

Please show full error message

请显示完整的错误消息

It would also help if you showed which line of code causes the error.

如果您显示哪一行代码导致错误,这也会有所帮助。

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'indexOf') at ResourcePath.fromString (path.ts:230:1) at collection (reference.ts:418:1) at getData (TodoPage.js:63:1)

未捕获(In Promise)TypeError:无法在getData(TodoPage.js:63:1)的集合(Reference.ts:418:1)的ResourcePath.from字符串(path.ts:230:1)读取未定义的属性(读取“”indexOf“”)

the line that caused is the const q

引起的线条是Const Q

That doesn't look like a reference to your code. Which line of your code causes the error? Please edit the question to add new data (don't add it in a comment).

这看起来不像是对您的代码的引用。您的代码的哪一行导致了错误?请编辑问题以添加新数据(不要将其添加到评论中)。

优秀答案推荐
更多回答

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com