redux 持久化:旧数据覆盖减速器 - 反应原生

问题描述

场景是用户相关的详细信息存储在一个减速器中。当用户 A 注销设备而用户 B 登录设备时,数据将被擦除,新用户数据将存储在减速器中。但是当应用程序关闭并从退出状态启动时,用户A的数据从persist中存储到reducer中。

我的商店配置代码如下:

import {createStore,compose,applyMiddleware} from 'redux';
import {persistStore,persistCombineReducers} from 'redux-persist';
import AsyncStorage from '@react-native-community/async-storage';
import {createLogger} from 'redux-logger';
import createSagaMiddleware from 'redux-saga';

import rootReducers from '../reducers'; // where reducers is a object of reducers
import sagas from '../sagas';

const config = {
  key: 'root',storage: AsyncStorage,blacklist: ['loadingReducer'],debug: true,//to get useful logging
};

const middleware = [];
const sagaMiddleware = createSagaMiddleware();

middleware.push(sagaMiddleware);

if (__DEV__) {
  middleware.push(createLogger());
}

const reducers = persistCombineReducers(config,rootReducers);

const rootReducer = (state,action) => {
  if (action.type === 'LOG_OUT') {
    return reducers(undefined,action);
  }
  return reducers(state,action);
};

const enhancers = [applyMiddleware(...middleware)];

const persistConfig = {enhancers};
const store = createStore(rootReducer,undefined,compose(...enhancers));
const persistor = persistStore(store,persistConfig,() => {
  //   console.log('Test',store.getState());
});
const configureStore = () => {
  return {persistor,store};
};

sagaMiddleware.run(sagas);

export default configureStore;

我尝试在用户尝试使用 AsyncStorage.removeItem('persist:root') 时使用 LOG_OUT ,但没有改变。旧数据即使应该被覆盖也被持久化。

知道是什么造成了这种奇怪的情况吗??

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...