TypeScript · Junior · Question 23 of 75
What is the type of the event in onChange for an <input> in React?
- ✓Correct answer:
React.ChangeEvent<HTMLInputElement> - 2
Event- the native DOM event - 3
InputEvent<string>from the standard library
Explanation
React uses its own synthetic events: ChangeEvent, MouseEvent<HTMLButtonElement>, FormEvent<HTMLFormElement> and so on. The generic specifies the element, so e.target.value is typed. If the handler is inline, the type is inferred automatically.