Answer the question
In order to leave comments, you need to log in
React. How to dynamically hang handlers?
How to dynamically hang handlers?
In jQuery, you can write anywhere on an element:
element.on("click",function(){});
element.off("click");
Answer the question
In order to leave comments, you need to log in
import React, { Component } from 'react';
class MyComponent extends Component {
// standard function bind
constructor(props) {
super(props);
this.onClickBar = this.onClickBar.bind(this);
}
onClickBar(event) {
// valid "this" only if bound in constructor
}
// babel-plugin-transform-class-properties is required for this syntax
onClickFoo = (event) => {
// "this" is always valid
};
render() {
return (
<div>
<button onClick={this.onClickFoo}>foo</button>
<button onClick={this.onClickBar}>bar</button>
</div>
);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question