React Native | Firebase authentication | Impossible to trigger navigator -


i’ve been stuck since 3 days problem. i’ve migrated app firebase , react native working charm except user authentication. i’m trying trigger navigator when user logs in. i’m using following method :

componentdidmount() {     firebase.auth().onauthstatechanged(function(user) {      if (user) {         global.userid = user.uid         alert(‘test’)                  var naviref = this.refs.navref         naviref.push({           ident: ‘home’         })     } else {       // no user signed in.     }  }); } 

i alert(‘test’) navigator nothing. if put naviref.push outside « onauthstatechanged » working. have no idea can now. there better solution using navigator ?

i think should trick:

componentdidmount() {     firebase.auth().onauthstatechanged((user) => {      if (user) {         global.userid = user.uid         alert(‘test’)                  var naviref = this.refs.navref         naviref.push({           ident: ‘home’         })     } else {       // no user signed in.     }  }); } 

now this inside function correct arrow function lexical binding of this. hence, can access this.refs.navref


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -