In this code, if I write add function like add = function(){} or add(){} , then I doesn't work. Are there some reasons?
class App extends.React.Component{
state = {
count: 0
};
add = () => {
console.log(‘add’);
this.setState({count: this.state.count + 1});
}
minus = () => {
console.log(‘minus’);
this.setState({count: this.state.count - 1});
}
render(){
return <div><Potato />
<div>class Component : {this.state.count}</div>
<button onClick={this.add}>add</button>
<button onClick={this.minus}>minus</button>
</div>
}
}