1

The handleChange() function is called whenever the input element is changed, but can't seem to access event.target.value.

Error Message

Property 'target' does not exist on type 'HTMLInputElement'.  TS2339

handleChange()

handleChange = (event:HTMLInputElement) => {
    console.log(event);
    const { name, value } = event.target;
    this.setState({[name]: value});
};

Input Element

<input name='email' type='email' value={this.state.email} onChange={this.handleChange} required />
Yusuf Abukar
  • 199
  • 1
  • 1
  • 9

1 Answers1

3

You have the wrong type on event. It's not an HTMLInputElement, it's an event. For change it's React.ChangeEvent<T> where T is the type of element you're using it on (HTMLInputElement in your case), so:

handleChange = (event: React.ChangeEvent<HTMLInputElement>) {
    // ...
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875