在反应中动态更改事件绑定的建议/最干净的方式是什么?如何在反应中重新绑定点击事件
例如,如果我最初在handleFirstClick
方法
handleFirstClick() {
//do other stuff
//rebind the button, so that next time it's clicked, handleSecondClick() would be called
}
有这样
<button type="button" onClick={this.handleFirstClick}>
一个按钮,然后在情况下,它不是完全清楚我的意思,这里就是想什么我使用jQuery代替React
$('#myButton').on('click', handleFirstClick);
function handleFirstClick() {
//other stuff
$('#myButton').off('click');
$('#myButton').on('click', handleSecondClick);
}
我不知道这是否是正确的方法,但我会对那个按钮计算点击次数的状态,并且有'handleClick()'相应地调用合适的功能。 –