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].
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
Share Improve this question edited Jul 3, 2018 at 3:35 Mayank Shukla 105k19 gold badges162 silver badges145 bronze badges asked Oct 17, 2017 at 5:00 Hamed MamdoohiHamed Mamdoohi 1311 silver badge6 bronze badges 1Warning: setState(...): Expected the last optional
callback
argument to be a function. Instead received: [object Promise].
- 1 You are calling the function there. Thus the return value is given as the second argument. – Dane Commented Oct 17, 2017 at 5:31
1 Answer
Reset to default 9It 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))
}