Skip to content

QuizNot attempted

Typing an input change handler

You extract onChange for an <input> into its own function. Which type should the event have?
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • ChangeEvent<HTMLInputElement>
  • React types an input's onChange as ChangeEventHandler<HTMLInputElement>, so the extracted function takes ChangeEvent<HTMLInputElement> and e.target.value is typed.
  • Not Event: the DOM Event isn't React's synthetic event and target is untyped.
  • Not MouseEvent: that is for clicks.
  • Not FormEvent<HTMLFormElement>: that is for a form's onSubmit.