【发布时间】:2016-08-26 08:34:22
【问题描述】:
我认为assign 应该创建一个新对象,这就是我在减速器中这样做的原因:
case types.ADD_ATTRIBUTE:
var newState = Object.assign({}, state)
newState.attributes[action.industry].push(action.attribute)
return Object.assign({}, state, newState);
case types.REMOVE_ATTRIBUTE:
var newState = Object.assign({}, state)
var removeIndex = newState.attributes[action.industry].indexOf(action.attribute)
newState.attributes[action.industry].splice(removeIndex, 1)
return Object.assign({}, state, newState);
但是,当我这样做时,组件不会触发更新 (componentWillReceiveProps)。它确实收到了新的 props,但 react-redux 内部的 shouldComponentUpdate 没有检测到更改。
我在这里做错了什么?
【问题讨论】:
标签: reactjs redux react-redux