我在这个问题上困扰了很长时间。我刚刚开始使用react-native-firebase在我的react-native应用程序中实现Firestore。我只是关注文档[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);
}
}
}
任何帮助将不胜感激!
答案 0 :(得分:4)
发生此错误是因为缺少本机RNFirestore模块。
yarn @react-native-firebase/firestore
之后,您需要运行pod install
并使用react-native run-ios
触发重建。
答案 1 :(得分:1)
如果您的Firebase / Firestore设置良好,那是因为您的查询为假,则可以使用以下方法进行测试:
import firestore from '@react-native-firebase/firestore';
firestore()
.collection('collection')
.onSnapshot((querySnapshot) => {
console.log(querySnapshot)
})