我怎么知道 redux-form resetForm() 完成了?

How can I know redux-form resetForm() is completed?

我在我的项目中使用 redux-form + react:

//My components
<button type="submit" className="btn btn-primary" onClick={this.getBuildingList.bind(this)}>Search</button>
<button type="button"  onClick={this.resetBuildForm.bind(this)}>Reset</button>

//resetBuildingForm function
resetBuildingForm(){
    let { dispatch, resetForm, list } = this.props;
    resetForm();
    //when I resetForm, I want to search again
    this.getBuildingList();
}

当我resetForm时,我想再次搜索,但是当我在redux-form中获取状态时,我得到的状态是旧的而不是新的,我怎么知道resetForm事件何时完成并且状态已更新?

当您的表单从 dirty 变为 pristine 时,您可以监听。

componentDidUpdate(prevProps) {
  if(this.props.pristine && !prevProps.pristine) {
    // we just reset
    this.getBuildingList()
  }
}

然后您只需调用 this.props.resetForm() 即可启动重置。

这可能对像我这样的新人有所帮助。 从 reduxForm 版本 6 开始,this.props.resetForm() 已经更改为 this.props.reset()

查看问题here