Open rafatwork opened 7 years ago
Hi! Sorry for the super late response to this but better late than never I hope. See code below on what I use to purge a reducer completely. The imported reducerVersion
is just a static variable that can be increased on new builds
import ReduxPersist from '../config/ReduxPersist';
import { AsyncStorage } from 'react-native';
import { persistStore } from 'redux-persist';
import { startup as startupAction } from '../modules/Startup';
const updateReducers = (store: Object) => {
const reducerVersion = ReduxPersist.reducerVersion;
const config = ReduxPersist.storeConfig;
const startup = () => store.dispatch(startupAction());
// Check to ensure latest reducer version
AsyncStorage.getItem('reducerVersion').then((localVersion) => {
if (localVersion !== reducerVersion) {
// Purge store
persistStore(store, config, startup).purge();
AsyncStorage.setItem('reducerVersion', reducerVersion);
} else {
persistStore(store, config, startup);
}
}).catch(() => {
persistStore(store, config, startup);
AsyncStorage.setItem('reducerVersion', reducerVersion);
});
};
export default {updateReducers};
Thank you for this functionality, is working great.
I was wondering: you now have to set an expire date on each reducer separately. In my use case, I just have to expire all the persisted data, regardless of which reducer it's part of. Is there a way of doing that?