在我的reducer中,我無法瞭解爲什麼我的狀態返回更新但未複製。React-Redux:狀態已更新但未複製
const loginReducer = (state = {}, action) => {
let newstate = JSON.parse(JSON.stringify(state))
const { type, payload } = action
switch(type) {
case constant.LOGIN_SUCCESS:
//
newstate = { login: [{ user: payload.user, password: payload.password, logged: true }] }
console.log(newstate.login)
break;
default:
break;
}
return newstate
}
當然這是我缺少的是什麼簡單的事情,但我想不出它
爲什麼你覺得你需要用'JSON.parse(JSON.stringify(州))'克隆? –