请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

如何清空redux

如何清空redux,我退出的时候需要清空redux数据,不然下次用其他账号登陆app还是显示的上个用户的数据

正在回答 回答被采纳积分+3

1回答

CrazyCodeBoy 2019-01-01 18:49:27

这个问题很好,以咱们的课程为例:

这是我们的reducer/index.js

const index = combineReducers({
    nav: navReducer,
    theme: theme,
    ...
});
export default index;

那么,该如何清空store呢,比如我们要在用户登出的时候清空store,我们可以这样做:

const appReducer = combineReducers({
    nav: navReducer,
    theme: theme,
    ...
});

const rootReducer = (state, action) => {
    if (action.type === 'USER_LOGOUT') {
        state = undefined;//清空store
    }
    return appReducer(state, action)
};
export default rootReducer;



2 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信