I have a question. How I can unbind the click of element in react? I have button, when I click on it, it increases score + 1, and after this click I want to remove it. How I can do this?
Help me please!
class Toggle extends React.Component {
constructor(props) {
super(props);
this.state = {
result: 2,
score: 0
};
this.getRes = this.getRes.bind(this);
}
getRes() {
if (this.state.result == 2) {
this.setState({score: this.state.score+1})
this.getRes.unbind(this);
}
}
render() {
return (
<div>
<div style={{paddingTop: 10}}>
<p>
<button>1</button>
<button onClick={this.getRes}>{this.state.result}</button>
</p>
<p>
<button>1</button>
<button onClick={this.getRes}>{this.state.result}</button>
</p>
<p>{this.state.score}</p>
</div>
</div>
);
}
}
ReactDOM.render(
<Toggle />,
document.getElementById('root')
);
this.state.score == this.state.scorebefalse?