setstate before function react 1

setstate before function react

this.setState(
  {newState: 'whatever'},
  () => {/*do something after the state has been updated*/}
)

Here is what the above code is Doing:
1. The first argument is the new state.
2. The second argument is a callback function that will be executed after the state has been updated.

Similar Posts