2016-08-23 91 views
1

我在项目中使用redux-form + react我如何知道redux-form resetForm()已完成?

//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的形式得到国家,我得到的状态是旧的,但不是新的,怎么能我知道什么时候resetForm事件完成并且状态被更新了?

回答

0

你可以听你的表格从dirtypristine

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

然后您可以拨打this.props.resetForm()来启动重置。

+0

非常感谢! – Liaoyf

1

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

查看问题here

相关问题