Can't get data from React-Native-Firebase(v6) Firestore: undefined is not a function (near '…this._firestore.native.collectionGet…')

青春壹個敷衍的年華 提交于 2021-01-21 13:47:33

问题


I've been stuck on this issue for so long. I just started implementing Firestore in my react-native application with react-native-firebase. 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.

This is in Android. Haven't tested in iOS yet.

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!


回答1:


This error occurs because the native RNFirestore module is missing.

After yarn @react-native-firebase/firestore you need to run pod install and trigger a rebuild with react-native run-ios.




回答2:


If you have a good firebase / Firestore setup so it's because your queries is false, you can test with something like that:

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

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


来源:https://stackoverflow.com/questions/59104680/cant-get-data-from-react-native-firebasev6-firestore-undefined-is-not-a-func

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!