这是我的 redux store 配置代码:
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,
whitelist: ['loginReducer'],
blacklist: ['profileReducer'],
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 enhancers = [applyMiddleware(...middleware)];
// const initialState = {};
const persistConfig = {enhancers};
const store = createStore(reducers, undefined, compose(...enhancers));
const persistor = persistStore(store, persistConfig, () => {
// console.log('Test', store.getState());
});
const configureStore = () => {
return {persistor, store};
};
sagaMiddleware.run(sagas);
export default configureStore;
问题是我必须手动重置每个减速器,以便将它们全部重置。当用户使用此存储配置注销时,有没有办法重置所有减速器?