谁能告诉我 React-Redux 状态管理?

时间:2021-06-26 15:59:55

标签: reactjs redux react-redux

this is the current structure of React-Redux store

在我初始化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

1 个答案:

答案 0 :(得分:1)

当我将传播状态传递给默认的减速器时,这个问题就解决了,比如: default: return { ...state };