Skip to content

QuizNot attempted

currentTarget vs target

In this handler, which line is a type error?
function onClick(e: React.MouseEvent<HTMLButtonElement>) {
console.log(e.currentTarget.disabled); // (1)
console.log(e.target.disabled); // (2)
}
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • (2): target is only EventTarget
  • The element generic types currentTarget, the element the handler is attached to, while target is whatever was actually clicked (maybe a child <span>), so React types it as plain EventTarget.
  • Not (1): currentTarget is HTMLButtonElement.
  • Not both: only target is loose.
  • Not neither: EventTarget has no disabled.
  • Likewise a bare ChangeEvent defaults to Element, so e.target.value fails until you write ChangeEvent<HTMLInputElement>.