I've tried for a week or more to make my state persisted in a react-native Android application but after rehydrating the state is always with initial values. If I check ASyncStorage contents or the state with Redux devtools, it is the initial states:
{
"status":"{\"actions\":[]}",
"list":"{\"actions\":[]}",
"map":"{\"site_ids\":{},\"alarmCounts\":[],\"geoJSON\":{}}",
"_persist":"{\"version\":-1,\"rehydrated\":true}"
}
I also get error Unexpected key "_persist" ...
when I use redux-reset and couldn't find any solution from Google.
If I run store.flush()
or store.purge()
, I don't see any changes in ASyncStorage.
My configureStore file is as follows. I think the problem is somewhere in here. Any help?
import { createStore } from "redux";
import { composeWithDevTools } from 'redux-devtools-extension';
import { persistStore, persistCombineReducers } from "redux-persist";
import reduxReset from 'redux-reset';
import { AsyncStorage } from 'react-native'
import userReducer from '../reducers/user';
import statusReducer from '../reducers/status';
import listReducer from '../reducers/list';
import mapReducer from '../reducers/map';
function reset(): void {
console.log('Reseting state');
store.dispatch({
type: 'RESET'
});
// persistor.purge();
};
function flush() {
console.log('FLUSH');
persistor.flush();
}
const enhancer = composeWithDevTools(
reduxReset()
);
const appReducer = persistCombineReducers(
{ // cfg
key: 'primary',
storage: AsyncStorage,
blacklist: ['user'],
throttle: 1000
},
{
user: userReducer,
status: statusReducer,
list: listReducer,
map: mapReducer
}
);
const rootReducer = (state, action) => {
return appReducer(state, action);
}
const store = createStore(
rootReducer,
enhancer
);
const persistor = persistStore(store, null);
export default { store, persistor, reset, flush };
I use [email protected], [email protected], [email protected]