Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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!

like image 821
Akshat Jain Avatar asked Nov 29 '19 12:11

Akshat Jain


People also ask

How do I fetch data from firestore in react native?

Step 1: Create a new React application. We use create-react-app to create our application. Step 2: Install the firebase package in the project using npm. Step 3: Create a new project from the Firebase dashboard by filling in the necessary details and check the format of the data that is stored in Firestore.

How do I get data from firebase in react native?

First, create a file called firebase-config. js in the root directory of your project to implement Firebase configuration and initialization. Now, go to the Firebase website. Click on the Get Started button and you will be taken to a page where you can create a new project.

How do I access my firestore database?

There are three ways to retrieve data stored in Cloud Firestore. Any of these methods can be used with documents, collections of documents, or the results of queries: Call a method to get the data once. Set a listener to receive data-change events.


2 Answers

This error occurs because the native RNFirestore module is missing.

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

edit: installing this modules requires you to re-bundle your application in android as well. run something like react-native run-android to do that.

like image 58
Petrus Theron Avatar answered Sep 20 '22 13:09

Petrus Theron


This issue resolves when you re-bundle and restart android dev server

like image 33
Kornelijus Sl Avatar answered Sep 20 '22 13:09

Kornelijus Sl