In my render() I have the following component with event handling.
render() { ...
<input type="text"
onChange={(_) => { this.restate("email", _.target.value); }} />
}
private restate(type: string, input: any) { ...
if (type === "email")
this.setState({ ... });
}
This works and behaves as supposed to. Since I'm learning React right now, I try to improve my syntax so it's smooth on the eyes. I've found this answer and liked the brevity of the event handler assignment. So I've changed my rendering and implemented the handler to be passed as follows.
render() { ...
<input type="text" onChange={ this.handleEmail } />
}
private handleEmail(data: React.ChangeEvent<HTMLInputElement>) {
console.log("hit before: " + data.target.value);
console.log(this);
this.restate("email", data.target.value);
}
The change in the markup seems to work, because the method handleEmail(...) is invoked. However, I get an error saying that restate(...) is not a method of undefined and, in fact, when I investigate what this is, I discovered it's undefined.
I need help understanding what I'm doing wrong and how it deviates from the article linked to above. I tried to google for the syntax differences between versions of React but got nothing. And I'm not sure how to describe the issue in correct technical terms.