我在这个问题上被困太久了。我刚刚开始在我的本机应用程序中使用react-本机-firebase实现Firestore。我只是在跟踪docs [https://invertase.io/oss/react-native-firebase/v6/firestore/quick-start#reading-data],但它对我不起作用。
这是在Android里。还没有在iOS上进行测试。
我一直在犯这个错误:
[TypeError: undefined is not a function (near '...this._firestore.native.collectionGet...')]
以下是相关代码:
import React, {Component} from 'react';
import { firebase } from '@react-native-firebase/firestore';
export default App extends Component{
constructor(props) {
super(props);
this.getData= this.getData.bind(this)
this.getData()
this.state = {};
}
async getData() {
try {
const querySnapshot = await firebase.firestore()
.collection('Gyms')
.get() //error with this
console.log('Documents', querySnapshot.docs);
} catch (e) {
console.log(e);
}
}
}任何帮助都将不胜感激!
发布于 2020-03-19 13:57:04
发生此错误是因为本机RNFirestore模块丢失。
在yarn add @react-native-firebase/firestore之后,您需要运行pod install并使用react-native run-ios触发重新构建。
编辑:安装这个模块也需要在android中重新捆绑应用程序。运行类似于react-native run-android的代码来实现这一点。
发布于 2020-01-12 21:21:24
如果您有一个很好的firebase / Firestore设置,这是因为您的查询是错误的,那么您可以使用这样的方法进行测试:
import firestore from '@react-native-firebase/firestore';
firestore()
.collection('collection')
.onSnapshot((querySnapshot) => {
console.log(querySnapshot)
})发布于 2021-09-03 07:24:55
当重新绑定并重新启动android dev server时,此问题将得到解决。
https://stackoverflow.com/questions/59104680
复制相似问题