在我的ComponentWillReceiveProps()
方法中,我的道具正在更新,仅从 API 中获取。请帮助如何恢复道具。
我的ComponentWillReceiveProps()
:
constructor(props) {
super(props)
this.state = {
filtered_chart_data: {}
}
props.getEngagementInfo()
props.getChartData()
}
componentWillReceiveProps(nextProps) {
const lastSavedCharts = this.state.filtered_chart_data
if (!_.isEmpty(nextProps.diagnose.chart_data)) {
if (_.isEmpty(this.state.filtered_chart_data)) {
return this.setState({
filtered_chart_data: nextProps.diagnose.chart_data
})
}
return this.setState(
{
filtered_chart_data: lastSavedCharts
},
() => this.updateFilters(nextProps.diagnose.chart_data)
)
}
}
updateFilters = chartDataToApplyFilters => {
if (!_.isEmpty(this.state.filtered_chart_data)) {
const { filters } = this.props.diagnose
this.handleFilterPlantRegion(
filters.plant_region,
chartDataToApplyFilters
)
this.handleFilterPlant(filters.plant, chartDataToApplyFilters)
}
}
在我nextProps
的变量nextProps.diagnose.chart_data
中,每次都在更新,但它是从 API 中获取的。
你能帮忙如何不更新这个道具吗?