React’s setState method with prevState argument

I’m new to React, just have a question on setState method. Let’s say we have a component:

class MyApp extends React.Component {

  state = {
    count: 3
  };

  Increment = () => {
    this.setState((prevState) => ({
      options: prevState.count + 1)
    }));
  }
}

so why we have to use prevState in the setState method? why can’t we just do:

this.setState(() => ({
  options: this.state.count + 1)
}));

Leave a Comment