Hello,
following this code:
class Counter extends React.Component {
constructor(props) {
super(props);
this.state = {
count: 0
};
this.increment = this.increment.bind(this);
}
increment() {
this.setState(state => ({
count: state.count + 1
}));
}
// Change code above this line
render() {
return (
<div>
<button className='inc' onClick={this.increment}>Increment!</button>
<h1>Current Count: {this.state.count}</h1>
</div>
);
}
};
If I write increment function like this ( with arrow function ):
increment = { () =>
this.setState(state => ({
count: state.count + 1
}));
}
I don’t need to bind it so I can deleted this ? :
this.increment = this.increment.bind(this);