【发布时间】:2017-02-19 00:37:57
【问题描述】:
考虑以下 Redux 代码,
let cacheState = {};
const mapStateToProps = (state, ownProps) => {
const zug = cacheState.bar === state.bar ? "qux" : "doo";
return {
foo: state.bar,
zug
};
cacheState = state;
};
此代码示例激发了以下观察:
1) 这似乎是在 Redux 组件中缓存状态的唯一方法
2) 如果从此模板创建了多个 Redux 组件,这将中断
3) 这是一种反模式
组件了解先前状态的正确方法是什么?
【问题讨论】: