redux-persist icon indicating copy to clipboard operation
redux-persist copied to clipboard

Redux Persist not working with RTK

Open uttu-316 opened this issue 3 years ago • 3 comments

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 avatar Aug 26 '22 05:08 uttu-316

@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

wtfabio avatar Oct 03 '22 14:10 wtfabio

I am facing the same problem. how did you solve it?

chahat151 avatar Jun 24 '24 18:06 chahat151