【发布时间】:2018-10-16 11:26:34
【问题描述】:
我有这样的生命周期钩子
componentDidUpdate(prevProps) {
// Typical usage (don't forget to compare props):
if (prevProps.activeItems !== this.props.activeItems) {
this.props.doAction();
}
}
props有这样的结构
[
{id:1, hidden: true},
{id:2, hidden: false}
{id:3, hidden: true}
]
我需要检查每个对象的 prev 和 next 属性中的 hidden 属性是否相同,所以我会知道是否需要在 if 条件下运行函数。我该怎么做?
【问题讨论】:
-
你真的不能,这是不可变数据结构的坏处。您必须手动进行检查,我使用
array.every,为此
标签: javascript reactjs