Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redux Persist not working with RTK #1407

Open
uttu-316 opened this issue Aug 26, 2022 · 1 comment
Open

Redux Persist not working with RTK #1407

uttu-316 opened this issue Aug 26, 2022 · 1 comment

Comments

@uttu-316
Copy link

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
Copy link

wtfabio commented Oct 3, 2022

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants