How to access custom attributes from event object in React?

前端 未结 15 2031
不思量自难忘°
不思量自难忘° 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:55

    To help you get the desired outcome in perhaps a different way than you asked:

    render: function() {
        ...
        
        ...
    },
    removeTag: function(i) {
        // do whatever
    },
    

    Notice the bind(). Because this is all javascript, you can do handy things like that. We no longer need to attach data to DOM nodes in order to keep track of them.

    IMO this is much cleaner than relying on DOM events.

    Update April 2017: These days I would write onClick={() => this.removeTag(i)} instead of .bind

提交回复
热议问题