I have my method
authHandler(authData){
if(!this.isMounted())
return;
const storeRef = myDatabase.ref(this.props.storeId);
storeRef.once('value', (snapshot) => {
const data = snapshot.val() || {};
if(!data.owner){
storeRef.set({
owner: authData.user.uid
});
}
this.setState({
uid: authData.user.uid,
owner: data.owner || authData.user.uid
});
// localStorage.setItem(`authData-${this.props.storeId}`, JSON.stringify(authData));
});
}
and here is the componentDidMount()
componentDidMount(){
app.auth().onAuthStateChanged(function(user, error){
if(!error && this.handleErrors){
this.handleErrors(error);
return;
}
if(user){
console.log(user);
this.authHandler(user);
}
});
}
But no matter what I do, it always throws:
TypeError: this.authHandler is not a function
I read through some similar questions: e.g. ReactJS - this.functionname is not a function
but none of them work for me.