rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.91k stars 862 forks source link

Redux Persist not working with RTK #1407

Open uttu-316 opened 1 year ago

uttu-316 commented 1 year ago
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?

wtfabio commented 1 year ago

@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

chahat151 commented 2 weeks ago

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