Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: setState(...): Expected the last optional callback argument to be a function

setState callback does not behave as expected, setState provide a callback to be called after the state changes, and the callback is an action of redux:

addressInput = e => {
 this.setState({
   address: e.target.value
 },
 this.props.filterSearch(this.state.address));
}

I get this error

Warning: setState(...): Expected the last optional callback argument to be a function. Instead received: [object Promise].

like image 605
Hamed Mamdoohi Avatar asked Jan 04 '23 07:01

Hamed Mamdoohi


1 Answers

It expect a "last optional callback argument to be a function".

Write it like this:

addressInput = e => {
  this.setState({
    address: e.target.value
  },
  () => this.props.filterSearch(this.state.address))
}
like image 158
Mayank Shukla Avatar answered Jan 06 '23 10:01

Mayank Shukla