首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法从React(V6)Firestore获得数据:未定义不是一个函数(接近‘...this._firestore.native.collectionGet.’)

无法从React(V6)Firestore获得数据:未定义不是一个函数(接近‘...this._firestore.native.collectionGet.’)
EN

Stack Overflow用户
提问于 2019-11-29 12:19:24
回答 3查看 4.3K关注 0票数 15

我在这个问题上被困太久了。我刚刚开始在我的本机应用程序中使用react-本机-firebase实现Firestore。我只是在跟踪docs [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...')]

以下是相关代码:

代码语言:javascript
运行
复制
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);
    }
  }
}

任何帮助都将不胜感激!

EN

回答 3

Stack Overflow用户

发布于 2020-03-19 13:57:04

发生此错误是因为本机RNFirestore模块丢失。

yarn add @react-native-firebase/firestore之后,您需要运行pod install并使用react-native run-ios触发重新构建。

编辑:安装这个模块也需要在android中重新捆绑应用程序。运行类似于react-native run-android的代码来实现这一点。

票数 14
EN

Stack Overflow用户

发布于 2020-01-12 21:21:24

如果您有一个很好的firebase / Firestore设置,这是因为您的查询是错误的,那么您可以使用这样的方法进行测试:

代码语言:javascript
运行
复制
import firestore from '@react-native-firebase/firestore';

firestore()
  .collection('collection')
  .onSnapshot((querySnapshot) => {
     console.log(querySnapshot)
  })
票数 1
EN

Stack Overflow用户

发布于 2021-09-03 07:24:55

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59104680

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档