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

Error getting documents [TypeError: undefined is not a function (near '...snapshot.forEach...')]

$
0
0

I'm recently practicing React Native and developed a login 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.

This is my code :

constructor() {
            super();
            this.state = {
             name: ''
            };
          }

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

<View style={styles.container}>
      <Image
          style={styles.background}        
          source={require('../assets/Rectangle121.png')}
      />        

     <TouchableOpacity  style={{position:"absolute", top:'9%', borderBottomColor:'black', borderRadius:5, alignItems:'center', justifyContent:'center' }} onPress={() => {this.handleUser(this.state.name)}} >
     <Image source={require('../assets/Rectangle204.png')} />
</View>
     </TouchableOpacity>

Error is :

Error getting documents [TypeError: undefined is not a function (near '...snapshot.forEach...')]

Do you have any suggestions? Thanks in advance for your help


Viewing all articles
Browse latest Browse all 28467

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>