React.js, wait for setState to finish before triggering a function?

前端 未结 5 713
庸人自扰
庸人自扰 2020-12-23 08:31

Here\'s my situation:

  • on this.handleFormSubmit() I am executing this.setState()
  • inside this.handleFormSubmit(), I am calling this.findRoutes(); - whic
5条回答
  •  南方客
    南方客 (楼主)
    2020-12-23 09:26

           this.setState(
            {
                originId: input.originId,
                destinationId: input.destinationId,
                radius: input.radius,
                search: input.search
            },
            function() { console.log("setState completed", this.state) }
           )
    

    this might be helpful

提交回复
热议问题