在我初始化reducer的地方,我已经像这样初始化了初始状态,
const initialState = {
isLogedIn: false
};
在发送一个 USER_SIGN_IN 动作后,我得到了一个额外的节点,如图所示。
export default (state = initialState, action) => {
switch (action.type) {
case USER_SIGN_IN:
return {
...state,
isLogedIn: true
};
case USER_SIGN_UP:
return {
...state,
user: {
firstName: action.payload.firstName,
lastName: action.payload.lastName,
email: action.payload.email
},
isLogedIn: false
};
default:
return {
state
};
};
};
谁能告诉我,为什么这会在 redux 中发生,我该如何解决?
这是一个 GitHub 存储库链接:https://github.com/Dawood-Shahid/TODO_Application
答案 0 :(得分:1)
当我将传播状态传递给默认的减速器时,这个问题就解决了,比如:
default: return { ...state };