3

I used the @react-native-firebase/firestore package for my React native app. I have installed my firebase/app as well and followed all the installation steps in the firebase web page. But I am not able to store data into my firestore. Here's the code I have used.

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

export const storeData = async (userDetails) => {
  let userName = userDetails.userName;
  let storeSuccess = await firestore()
    .collection('Users')
    .doc('123')
    .set({
      username: userDetails.userName,
      userselfie: userDetails.userSelfie,
      LP: userDetails.LPImage,
      bill: userDetails.BillImage,
      customercontact: userDetails.customerContact,
      date: userDetails.date,
      time: userDetails.time,
    })
    .then(() => console.log('success'))
    .catch((error) => {
      error.message && alert(error.message);
      console.log(
        'Something went wrong while adding user data to firestore: ',
        error,
      );
      return 'error';
    });
  return storeSuccess;
};

I have done everything and the above function is even getting called but I get a {"_U": 0, "_V": 0, "_W": null, "_X": null} as a response from the firestore function.

Jenipha
  • 41
  • 2

1 Answers1

0

Using async/await along with Promise.then() may be causing this unexpected behavior. In order to fix your function, delete the async/await and instead keep the then() notation as follows:

export const storeData = (userDetails) => {
let userName = userDetails.userName; 
let storeSuccess = firestore()
.collection('Users')
    .doc('123')
    .set({
      username: userDetails.userName,
      userselfie: userDetails.userSelfie,
      LP: userDetails.LPImage,
      bill: userDetails.BillImage,
      customercontact: userDetails.customerContact,
      date: userDetails.date,
      time: userDetails.time,
    })
    .then(() => console.log('success'))
    .catch((error) => {
      error.message && alert(error.message);
      console.log(
        'Something went wrong while adding user data to firestore: ',
        error,
      );
      return 'error';
    });
  return storeSuccess;
};
Farid Shumbar
  • 1,360
  • 3
  • 10