alisongaleon alisongaleon - 2 months ago 6x
React JSX Question

Button with FontAwesome child makes the button target value undefined

I can't seem to figure how to solve this problem that if you click a react-bootstrap button with a fontawesome icon as a child, the

target value
will be undefined.

But if you click just outside the text with the icon and still inside the button, the
handler will still work.


The issue seems to be that can change depending on where in the button you click. Using event.currentTarget instead should give you the results you're looking for.

onClick(e) {
  const btnValue = e.currentTarget.value

See also: What is the exact difference between currentTarget property and target property in javascript