React this.setState() method

So the handleChange method comes out to be

handleChange(event){

  this.setState({
    input: event.target.value
  });
}

My previous (probably faulty) understanding of the setState() method was if the new state to be set was dependent of the previous state, “state” would be the argument of the method. If not, the new state would be stated without reference to the current state.

I arrived to this understanding after being somewhat puzzled by the setState() method arguments from the previous “write a simple counter” challenge.

increment() {
    this.setState(state => ({  
      count: state.count + 1 //new count is PREVIOUS COUNT + 1, this.SetState(state => ({})
    }));
  
reset() {
    this.setState({
      count: 0           //New count is 0 regardless of previous value, so this.setState({})
    });
  }

How is my current understanding wrong? How come the setState() method in the handleChange method from earlier not have state as an argument? And what exactly is “event”?

Another thing; so far I haven’t had many problems working through the curriculum. Everything has been quite smooth although I’m finding this react section somewhat mind-bending. I’ve done every challenge and project prior yet it feels like there’s a huge gap in my knowledge I was meant to address before working with React?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.