在反應中動態更改事件綁定的建議/最乾淨的方式是什麼?如何在反應中重新綁定點擊事件
例如,如果我最初在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()'相應地調用合適的功能。 –