I'm struggling to understand why my authHandler function is returning the error "cannot read property 'controls' of undefined" even though I have defined it. At least, I believe I have - see below.
Any fresh perspectives on this issue would be greatly appreciated!
class SignUp extends Component {
state = {
controls: {
email: {
value: "",
valid: false,
validationRules: {
isEmail: true
},
touched: false
},
password: {
value: "",
valid: false,
validationRules: {
minLength: 6
},
touched: false
}
}
};
authHandler = () => {
return new Promise (function(resolve, reject) {
const authData = {
email: this.state.controls.email.value,
password: this.state.controls.password.value
};
this.props.onTryAuth(authData, this.state.authMode);
})
.then(() => {
this.props.onAddUserData(
this.state.controls.userName.value,
)
})
.catch(err => {
console.log(err);
alert("Oops! Something went wrong, please try again")
})
};