【问题标题】:Get the difference between next-props and props获取 next-props 和 props 的区别
【发布时间】:2017-02-28 11:32:46
【问题描述】:

基本上,我想找出 nextprops 和 nextState 之间的区别。两者都包含一个包含对象的数组。 如果道具之间有任何不同,那么我会将特定道具添加到状态中。

componentWillReceiveProps(nextProps, nextState) {

}

我能够找到 npm 包调用 react-addons-shallow-compare,但它对我不起作用。请在下面找到代码。

componentDidUpdate(prevProps, prevState) {
    console.log("nextProps.workers && this.state.fetchAction ",prevProps," && ",prevState);
    let status = shallowCompare(this, prevProps, prevState);
    console.log("status ",status);

}

每次返回true。即使道具是两个不同的。请帮我解决这个问题。

【问题讨论】:

标签: javascript node.js reactjs redux react-redux


【解决方案1】:

如果你使用下划线,你可以这样做

_.isEqual(this.props, nextProps);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-30
    • 2015-03-15
    • 2021-11-20
    • 2022-11-13
    • 1970-01-01
    • 2021-02-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多