如何清空redux

来源:11-

qq_一美金_0

2018-12-31

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

写回答

1回答

CrazyCodeBoy

2019-01-01

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

这是我们的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
0

RN入门到进阶,打造高质量上线App

解锁React Native开发应用新姿势,React Native新版本热门技术

3197 学习 · 3260 问题

查看课程