Using async setState

前端 未结 5 2137
清歌不尽
清歌不尽 2020-11-28 04:42

I have function which dispatched an action. I would like to display a loader before and after the action. I know that react composing the object passed to setState

5条回答
  •  臣服心动
    2020-11-28 05:15

    Here's what you can do...

    1. Change your action to take in a onFetchComplete callback, along with the input.
    2. Change your handleChange to -

      handleChange(input) {
          this.setState({ load: true }, ()=>
              this.props.actions.getItemsFromThirtParty(input,
              ()=>this.setState({ load: false }))
          );
      }
      

    This will ensure the action processor code can invoke back your state change callback even if it's not written in a promise based fashion.

提交回复
热议问题