我走了ComponentWilleReceiveProps路由.鉴于cloneWithRows
每次更新时都需要一个新对象(取决于使用rowHasChanged
的方式),因此需要向其传递一组新数据.幸运的是,对于redux Reducer,就返回的数据而言,这种模式在任何情况下都是可以预期的.
以下是我如何在自己的应用程序中做到这一点:
componentWillReceiveProps(newProps) {
let days = newProps.days;
if (newProps.viewingDayUuid !== this.props.viewingDayUuid) {
days = days.map((day) => {
if (day.uuid === newProps.viewingDayUuid || day.uuid === this.props.viewingDayUuid) {
return Object.assign({}, day);
} else {
return day;
}
});
}
this.setState({
dataSource: this.state.dataSource.cloneWithRows(days)
});
}
如果你可以忽略if块,那就是如果列表视图中当前选中的(高亮显示状态)导航项需要更改,我决定创建一个新的day对象.而不是每次都返回全新的对象