无法从React-Native-Firebase(v6)Firestore获取数据:undefined不是函数(在"...“”this.“”_firestore.native.collectionGet..."“附近)

xa9qqrwz  于 2023-01-27  发布在  React
关注(0)|答案(3)|浏览(113)

我已经在这个问题上纠结了很长时间了。我刚刚开始在我的react-native-firebase应用程序中实现Firestore。我只是按照文档[https://invertase.io/oss/react-native-firebase/v6/firestore/quick-start#reading-data]操作,但它对我不起作用。
这是安卓系统,还没有在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);
    }
  }
}

任何帮助将不胜感激!

az31mfrm

az31mfrm1#

发生此错误的原因是缺少本机RNFirestore模块。
yarn add @react-native-firebase/firestore之后,您需要运行pod install并使用react-native run-ios触发重建。
编辑:安装这个模块需要你在android中重新捆绑你的应用程序。运行类似react-native run-android的程序来完成。
如果你在m1机器上使用expo,那么首先在你的ios捆绑包中安装cd,然后运行:

arch -x86_64 pod install
pprl5pva

pprl5pva2#

如果你有一个很好的firebase / Firestore设置,所以它是因为你的查询是假的,你可以用这样的东西测试:

import firestore from '@react-native-firebase/firestore';

firestore()
  .collection('collection')
  .onSnapshot((querySnapshot) => {
     console.log(querySnapshot)
  })
avwztpqn

avwztpqn3#

当您重新捆绑并重新启动android dev server时,此问题将得到解决

相关问题