[英]Can't get data from React-Native-Firebase(v6) Firestore: undefined is not a function (near '...this._firestore.native.collectionGet...')
I've been stuck on this issue for so long.我在这个问题上纠结了这么久。 I just started implementing Firestore in my react-native application with react-native-firebase.
我刚刚开始使用 react-native-firebase 在我的 react-native 应用程序中实施 Firestore。 I'm just following the docs [ https://invertase.io/oss/react-native-firebase/v6/firestore/quick-start#reading-data] but it doesn't work for me.
我只是在关注文档 [ https://invertase.io/oss/react-native-firebase/v6/firestore/quick-start#reading-data]但它对我不起作用。
This is in Android.这是在安卓中。 Haven't tested in iOS yet.
还没有在 iOS 中测试过。
I keep getting this error:我不断收到此错误:
[TypeError: undefined is not a function (near '...this._firestore.native.collectionGet...')]
Here's the relevant code:这是相关代码:
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);
}
}
}
Any help would be much appreciated!任何帮助将非常感激!
This error occurs because the native RNFirestore module is missing.出现此错误是因为缺少本机 RNFirestore 模块。
After yarn add @react-native-firebase/firestore
you need to run pod install
and trigger a rebuild with react-native run-ios
.在
yarn add @react-native-firebase/firestore
之后,您需要运行pod install
并使用react-native run-ios
触发重建。
edit: installing this modules requires you to re-bundle your application in android as well.编辑:安装此模块还需要您在 android 中重新捆绑您的应用程序。 run something like
react-native run-android
to do that.运行类似
react-native run-android
东西来做到这一点。
If you have a good firebase / Firestore setup so it's because your queries is false, you can test with something like that:如果你有一个很好的 firebase / Firestore 设置,那是因为你的查询是错误的,你可以用类似的东西进行测试:
import firestore from '@react-native-firebase/firestore';
firestore()
.collection('collection')
.onSnapshot((querySnapshot) => {
console.log(querySnapshot)
})
This issue resolves when you re-bundle and restart android dev server当您重新捆绑并重新启动 android 开发服务器时,此问题会解决
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.