我有一个来自React
的示例,其中组件更新取决于props
是对象还是数组类型。使用reselect
库和Redux store
。它是否像这样,意味着新对象将不等于prevprops
?如果可以这样工作,那么我如何使用redux
中的对象和新道具,以便shouldComponentUpdate
中发生对象更改时props
对我有用?>
答案 0 :(得分:1)
Reducer函数错误,CounterReducer.js,第10行
return {
...state,
// don't set this directly, this code preserves the reference to the array and react does not updates the
counter: state.counter
// counter: Array.from(state.counter)
};
检查我更新的代码,您正在上面的代码中设置引用,并用此代码替换上面的代码。
return {
...state,
//counter is now a new array
counter: [...state.counter]
// counter: Array.from(state.counter)
};