So the following code is in Angular 4 and I can\'t figure out why it doesn\'t work the way as expected.
Here is a snippet of my handler:
onUpdatingSe
Passing HTMLInputElement as a generic to the event type should work too:
onUpdatingServerName(event: React.ChangeEvent<HTMLInputElement>) {
console.log(event);
this.newserverName = event.target.value;
}
I was looking for a solution to a similar TypeScript error with React:
Property 'dataset' does not exist on type EventTarget in TypeScript
I wanted to get to event.target.dataset
of a clicked button element in React:
<button
onClick={onClickHandler}
data-index="4"
data-name="Foo Bar"
>
Delete Candidate
</button>
Here is how I was able to get the dataset
value to "exist" via TypeScript:
const onClickHandler = (event: React.MouseEvent<HTMLButtonElement>) => {
const { name, index } = (event.target as HTMLButtonElement).dataset
console.log({ name, index })
// do stuff with name and index…
}