2016-08-23 89 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

相關問題