在我的應用程序,我需要轉換異步同步(即)一次的setState設置的值,然後我需要在後期調用如何使的setState在陣營同步過程
logChange(val) {
this.setState({
fetchIntentReport: {
startDate: this.state.fetchIntentReport.startDate,
endDate: this.state.fetchIntentReport.endDate,
intents: val.split(','),
},
});
this.props.fetchIntentReports({
startDate: this.state.fetchIntentReport.startDate,
endDate: this.state.fetchIntentReport.endDate,
intents: this.state.fetchIntentReport.intents,
});
}
一旦獲取來自API的數據值設置爲意圖,那麼我需要通過REDX調用fetchIntentReports API調用。
的[的setState(https://facebook.github.io/react/docs/react-component.html#setstate)方法接受一個回調作爲第二個參數。沒有辦法使它真正同步,正如文檔中所解釋的,它更像是一個請求。 – Leandro