反应16.在回调中两次更改setstate

时间:2018-07-04 13:58:03

标签: reactjs

我正尝试禁用两次单击以手动提交:此代码有效吗?

export class CrudToolBar extends Component {
  constructor(props) {
    super(props);
    this.state = {
      clicked: false,
    };
  }

  changePageCtrl = (props, url, isFunction = false) => {
    if (isFunction) {
      this.props.toolbarFunctions(url, {t: props.t});
    } else {
      this.props.containerPropsForm.goUrl(url);
    }
  };

  handleClick = (e) => {
    if (!this.state.clicked) { // TWIN CTR231 ctrl is not saving this

      this.setState( {clicked: true} , async () => {
        this.props.appSubmitStart();
        await this.props.handleSubmit();
        this.props.appSubmitStop();
        this.setState( {clicked: false});
      });
    }
  };

但是我得到了:

Warning: Can only update a mounted or mounting component. This usually means you called setState, replaceState, or forceUpdate on an unmounted component. This is a no-op.

Please check the code for the FormContainer component

在回调内部不是很好的常规状态吗?

0 个答案:

没有答案