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
Post a Comment