如何解决找不到变量FieldValue,React Native / Firebase
尝试使用arrayRemove从Firebase数组中删除项目,但出现以下错误:
ReferenceError: Can't find variable: FieldValue
const removeItemHandler = () => {
//this logs the array item like is should,dont think this value is the issue
console.log(props.item)
console.log(props.currentNote)
//removes note from the notes array
db.collection('users').doc(userEmail)
.collection('books').doc(props.currentBook)
.collection('specific').doc(props.currentNote).update({
notes: FieldValue.arrayRemove(props.item)
})
showRemoveButton(false)
}
我正在跟踪下面的链接示例,真的不确定为什么我的非常相似的情况会给我这个错误。谢谢!
https://firebase.googleblog.com/2018/08/better-arrays-in-cloud-firestore.html
此外,请记住props.item引用了数组项的名称,我用console.log的类型和值进行了检查,它是正确的。有信心这不是问题的一部分。
解决方法
您正在访问未定义的FieldValue
。您不能直接访问它。
您可以通过firebase.firestore.FieldValue
进行访问,也可以直接导入firestore.FieldValue
来访问它。因此,像这样更改代码:
const removeItemHandler = () => {
//this logs the array item like is should,dont think this value is the issue
console.log(props.item)
console.log(props.currentNote)
//removes note from the notes array
db.collection('users').doc(userEmail)
.collection('books').doc(props.currentBook)
.collection('specific').doc(props.currentNote).update({
notes: firebase.firestore.FieldValue.arrayRemove(props.item)
notes: firestore.FieldValue.arrayRemove(props.item) // or if you are imported firestore
})
showRemoveButton(false)
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。