【发布时间】:2018-02-07 09:43:42
【问题描述】:
我的 Reactjs-Redux 应用程序中有这段代码
switch (action.type) {
case SET_RISPOSTA:
const newState = {...state}
newState.verifica.domande[action.indexDomanda].risposte[action.indexRisposta].valore = action.valore
console.log(state.verifica.domande[0].risposte[0].valore) console.log(newState.verifica.domande[0].risposte[0].valore)
return newState
default:
return state
}
我希望控制台显示
未定义(未定义的值) 1(action.valore 的价值)
但控制台显示
1 1
即使我使用了 {...state},为什么我的状态对象发生了变异?
如果我放了
console.log(state.verifica.domande[0].risposte[0].valore)
之前
const newState = {...state}
控制台显示
未定义 1
【问题讨论】:
-
这是我的第一个 Stack Overflow 问题!