How to access custom attributes from event object in React?

前端 未结 15 2041
不思量自难忘°
不思量自难忘° 2020-11-27 09:27

React is able to render custom attributes as described at http://facebook.github.io/react/docs/jsx-gotchas.html:

If you want to use a custom attribut

15条回答
  •  萌比男神i
    2020-11-27 10:13

    If anyone is trying to use event.target in React and finding a null value, it is because a SyntheticEvent has replaced the event.target. The SyntheticEvent now holds 'currentTarget', such as in event.currentTarget.getAttribute('data-username').

    https://facebook.github.io/react/docs/events.html

    It looks like React does this so that it works across more browsers. You can access the old properties through a nativeEvent attribute.

提交回复
热议问题