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