How to access custom attributes from event object in React?

前端 未结 15 2062
不思量自难忘°
不思量自难忘° 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条回答
  •  日久生厌
    2020-11-27 09:53

    event.target gives you the native DOM node, then you need to use the regular DOM APIs to access attributes. Here are docs on how to do that:Using data attributes.

    You can do either event.target.dataset.tag or event.target.getAttribute('data-tag'); either one works.

提交回复
热议问题