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!
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.
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.
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.
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.
This issue resolves when you re-bundle and restart android dev server
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With