[英]hey i am trying to build a blogging application using react-native and firebase as my primary database
Hey i am trying to build a blog app but i am facing an error in the posting of the blog and i think the error is in the file 'screens/main/Home.js' that says 'Type Error: null is not an object (evaluating quearySnapshot.forEach')'嘿,我正在尝试构建一个博客应用程序,但我在发布博客时遇到错误,我认为错误出现在文件“screens/main/Home.js”中,上面写着“类型错误:null 不是 object (评估 quearySnapshot.forEach')'
source code: https://github.com/Sakshamz4554/reactnativeblogapp源代码: https://github.com/Sakshamz4554/reactnativeblogapp
The above error is due to quearySnapshot in your code is not an array but null.上述错误是由于您的代码中的quearySnapshot不是数组,而是 null。 Before using an array operation to a variable, it's always better to check if its value is not null and have length more than 0 like shown below
在对变量使用数组操作之前,最好检查它的值是否不是 null 并且长度大于 0,如下所示
function getBlogData() {
firestore().collection('usersBlog')
.doc(auth().currentUser.uid)
.collection('blogs')
.onSnapshot((quearySnapshot) => {
const data = []
quearySnapshot?.length > 0 && quearySnapshot.forEach((documentSnapshot) => {
data.push({
...documentSnapshot.data(),
id: documentSnapshot.id
})
})
setBlogs(data)
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.