Reactjs 将任何操作发送到redux,以清除状态的其他部分

Reactjs 将任何操作发送到redux,以清除状态的其他部分,reactjs,redux,Reactjs,Redux,当我尝试调用redux中的任何其他操作时,它将状态的一部分设置为它的initialState 我的除根剂看起来像这样 const rootReducer = combineReducers({ credentials: combineReducers({ cred, user, partner, merchant, bank, error, auth, }), preCredentials, theme, }); 正在

当我尝试调用redux中的任何其他操作时,它将状态的一部分设置为它的
initialState

我的除根剂看起来像这样

const rootReducer = combineReducers({
    credentials: combineReducers({
    cred,
    user,
    partner,
    merchant,
    bank,
    error,
    auth,
  }),
  preCredentials,
  theme,
});
正在清除的状态部分是
主题

为什么这个与主题减缩器有关的操作可以改变它的状态

主题减缩器

function theme(state = { ...INITIAL_THEME }, action) {
  switch (action.type) {
    case LOADING_THEME:
      return {
        ...state,
        isLoading: true,
      };
    case SAVE_THEME:
      return {
        ...action.theme,
        error: {
          status: null,
          message: '',
        },
        isLoading: false,
      };
    case CLEAR_THEME:
      return INITIAL_THEME;
    default:
      return INITIAL_THEME;
  }
}
调度减小器

function preCredentials(state = { ...INITIAL_STATE }, action) {
  switch (action.type) {
    case SAVE_USERNAME:
      return { ...state,
        user: { ...state.user,
          fullName: action.fullName,
        },
      };
    default:
      return state;
  }
}
返回状态而不是初始状态


返回状态而不是初始状态

,因为当您调度除
加载主题以外的任何操作时,SAVE\u THEME
将清除您的状态,因为它将成为
默认值
,不要在那里返回
初始主题
,而是返回
{…state}
,因为当您调度除
加载主题以外的任何操作时,保存主题
它将清除您的状态,因为它将进入
默认
,不要在那里返回
初始主题
,而是返回
{…状态}
function theme(state = { ...INITIAL_THEME }, action) {
  switch (action.type) {
    case LOADING_THEME:
      return {
        ...state,
        isLoading: true,
      };
    case SAVE_THEME:
      return {
        ...state,
        ...action.theme,
        error: {
          status: null,
          message: '',
        },
        isLoading: false,
      };
    case CLEAR_THEME:
      return INITIAL_THEME;
    default:
      return state;
  }
}