Two ways to update the state in React.js

In any class-based component, there are two ways we can update the state, and below is a brief explanation.

  1. The first one
this.setState({name: { first: "John", last: "Doe" }});
  1. The second one
this.setState(
    (state, props) => {
        return {...newState}
    },
    () => {
        console.log("I'm the callback function!");
    }
);