javascriptfirebasereact-nativegoogle-cloud-firestoreexpo

How can you display text from Firestore?


I am trying to make an app with React Native, Firebase, and Expo that shows text that is loaded from the Firestore.

For example, I want the app to display "helloworld".

My Firebase backend looks like this: screenshot of Firebase data

But I don't know how to load the text from Firestore into the app and how to display it.


Solution

  • First add library 'react-native-firebase'

    import firebase from 'react-native-firebase';
    

    Then get the data from firestore using below function

    getDataFromFirebase(){
    firebase.firestore().collection('testcollections').doc(testdoc).get()
         .then((doc) => {
            if (doc.exists) {
              console.log("Document data: ", doc.data().testfield);
            }else{
              console.log("Document data is not empty: ");
            }
          })
        .catch(error => {
          console.log('firebase Error::'+error)
         })
    }