Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 28468

How to retrieve data from Firebase of a selected item in React Native?

$
0
0

I'm recently practicing React Native and developed a login-signup-homescreen form attached to Firebase. I'm trying to get the username from the database and print the name of the logged-in user on the screen. I want to retrieve a single data (username) from the database and add it to the screen. The name of the logged-in user must be added to the screen. But the code takes all the data and I can't figure out the logic of adding it to the screen.

handleUser = () => {
    const db = firebase.firestore();
    console.log('mounted')
    const usersRef = db.collection('users').where('name', '==', 'johny');
    const allUsers = usersRef.get()
      .then(snapshot => {
        snapshot.forEach(doc => {
          console.log(doc.id, '=>', doc.data());
        });
      })
      .catch(err => {
        console.log('Error getting documents', err);
      });

Instead of "Megan Gibson" I want to print the username I pulled from the database.

<Text onChangeText= {text => onChangeText(this.handleUser(this.state.usersRef))} >Megan Gibson</Text>

Viewing all articles
Browse latest Browse all 28468

Trending Articles