Brian Anderson
Brian Anderson

Reputation: 237

React Native Firebase Cloud Firestore

Using the React Native Firebase Basic Starter Kit I am unable to add data to my cloud firestore running the application in the Android emulator. The only code I have added to the project is in App.js in componentDidMount which is the following:

componentDidMount() {
  firebase.firestore().collection('xyz').add({
     description: 'Engineering',
     id: 1,
     name: 'Engineering'
  }).then(function (docRef) {
     console.log("Document written with ID: ", docRef.id);
  }).catch(function (error) {
     console.error("Error adding document: ", error);
  });

}

The app runs just fine and I see the starting screen, but I never get a response back from add; no resolve or reject from the call. My Firebase project is a new project and I've added Android access to it using the wizard and placed the google-services.json file in the appropriate folder (android/app). Using the remote debugger I never see any of my logs confirming success or failure. Also worth noting is that my database is completely empty because it's new.

react: 16.3.1 react-native: 0.55.3 react-native-firebase: 4.1.0

Any help would be appreciated.

Upvotes: 0

Views: 542

Answers (1)

A Lower
A Lower

Reputation: 61

A very late answer, but in case someone else sees it...

I had the same issue and couldn't find the answer. I realised that I had a bit of code that was listening for the state change of the user. I was signing in and it was redirecting me off without finishing the update on the user.

firebaseApp.auth().onAuthStateChanged(user => {
    this.props.navigation.navigate(user ? 'Home' : 'Login')
})

I removed this and I was getting an error back. Fixed the error and using set() to add a document works like a charm.

Upvotes: 1

Related Questions