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

问题描述 投票:8回答:1

我在这个问题上困扰了很长时间。我刚刚开始使用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);
    }
  }
}


任何帮助将不胜感激!

javascript firebase react-native google-cloud-firestore react-native-firebase
1个回答
1
投票

如果您的Firebase / Firestore设置良好,那是因为您的查询为假,则可以使用类似的测试:

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

firestore()
  .collection('collection')
  .onSnapshot((querySnapshot) => {
     console.log(querySnapshot)
  })
© www.soinside.com 2019 - 2024. All rights reserved.