redux-persist
redux-persist copied to clipboard
Redux Persist not working with RTK
import AsyncStorage from '@react-native-async-storage/async-storage';
import {configureStore} from '@reduxjs/toolkit';
import {
persistStore,
persistReducer,
FLUSH,
REHYDRATE,
PAUSE,
PERSIST,
PURGE,
REGISTER,
} from 'redux-persist';
import {rootReducer} from './reducers';
const persistConfig = {
key: 'Root',
version: 1,
storage: AsyncStorage,
};
const persistedReducer = persistReducer(persistConfig, rootReducer);
export const store = configureStore({
reducer: persistedReducer,
middleware: getDefaultMiddleware =>
getDefaultMiddleware({
serializableCheck: {
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
},
}),
});
export const persistor = persistStore(store);
import {combineReducers} from '@reduxjs/toolkit';
import postReducer from './post_reducer';
import profilereducer from './profile_reducer';
import utilReducer from './utils_reducer';
export const rootReducer = combineReducers({
utilities: utilReducer,
profile: profilereducer,
post: postReducer,
});
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<AppNavigator />
<PersistGate>
</Provider>
My redux actions are working correctly and the store updates each dispatch. But the state is not persisting on refreshing or reopening the app.
What to do in this case?
@uttu-316, persistence is working for me following the official documentation on RTK + redux-persist. Check it out here: https://redux-toolkit.js.org/usage/usage-guide#use-with-redux-persist
I am facing the same problem. how did you solve it?