Can anybody tell me why I am getting this.setState is not defined error in the code below?
componentDidMount(){
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
this.setState({user:user});
console.log(user.uid);
} else {
this.setState({user:null});
console.log("logged out");
}
});
}
I tried different approaches also:
componentDidMount(){
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
//this.setState({user:user});
this.sState(user);
console.log(user.uid);
} else {
this.setState({user:null});
console.log("logged out");
}
});
}
sState(user){
this.setState({user:user});
}
For the above, the error is this.sState is not a function.
I checked out the similar questions in SO they don't seem to be helpful in my case. Thanks..