As I am learning react at the moment I came across this concept of event handler using "setState".
It is a little complicated for my understanding as 3 functions within each other. Case in point.
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}))
}
//....some other code
This code works. I tried to understand the increment function a little further but I can't understand why the following code will not work:
increment(){
this.setState(function anon(state){
count: state.count+1
})
}
What is wrong with this code?