最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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

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

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 1
  • 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
Add a ment  | 

1 Answer 1

Reset to default 9

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))
}
发布评论

评论列表(0)

  1. 暂无评论