What I am trying?
Trying to set the value of input type text in state
What did I search so far?
React - uncaught TypeError: Cannot read property 'setState' of undefined
but this does not answer my issue
Error Details
TypeError: Cannot read properties of undefined (reading 'setState')
This error is coming when setting the value of email in the function setEmailVal
Component
import React from 'react';
class Login extends React.Component {
constructor(props) {
super(props);
this.state = {email: ""};
}
setEmailVal(val) {
this.setState({email: val.currentTarget.value});
}
render() {
return (
<input type="text" onChange={this.setEmailVal} value={this.state.email} />
);
}
}
export default Login;