我正在尝试限制react-rexdux connect()触发重新渲染的次数。我看过这里的文档...
https://github.com/reduxjs/react-redux/blob/master/docs/api.md
..。假设有一种方法可以通过为areStatesEqual编写自己的配置选项函数来防止重新呈现。问题是,我的简单console.log测试显示这个选项永远不会触发!不知道我做错了什么。关于这个特性的文档并不多,甚至连一个例子都没有。
export const mapStateToProps = (state, ownProps) => Object.assign({
isMobileLayout: state.deviceWidthReducer.width < 480,
postalCode: state.userReducer.postalCode,
productImageGroup: state.productReducer.productImageGroup,
productId: '05047234',
}, ownProps);
export default connect(
mapStateToProps,
null,
null,
{
pure: true,
areStatesEqual: (next, prev) => {
console.log('areStatesEqual?'); // <-- THIS NEVER GETS LOGGED.
return next.productId === prev.productId;
},
},
)(Product);在开发工具中设置断点,断点也永远不会触发。

发布于 2018-08-11 15:22:50
https://github.com/reduxjs/react-redux/issues/592 -这可能是相关的/解释了一点或具有误导性;)
试试undefined而不是null?但我不知道这有什么关系。
使用“标准”shouldComponentUpdate优化?
https://stackoverflow.com/questions/51791937
复制相似问题