Source: app/store.jsx

  1. import { configureStore } from '@reduxjs/toolkit'
  2. import {
  3. persistStore,
  4. persistReducer,
  5. FLUSH,
  6. REHYDRATE,
  7. PAUSE,
  8. PERSIST,
  9. PURGE,
  10. REGISTER,
  11. } from 'redux-persist'
  12. import storage from 'redux-persist/lib/storage';
  13. import pokemonsReducer from '../features/pokemons/pokemonsSlice'
  14. /**
  15. * Configuration object for redux-persist.
  16. * Only objects on the whitelist are stored.
  17. * @const persistConfig
  18. */
  19. const persistConfig = {
  20. key: 'root',
  21. version: 1,
  22. storage,
  23. whitelist: ['ids', 'entities', 'status', 'error']
  24. };
  25. /**
  26. * Persisted reducer
  27. * @const persistedReducer
  28. */
  29. const persistedReducer = persistReducer(persistConfig, pokemonsReducer);
  30. /**
  31. * The Redux store.
  32. * @const store
  33. */
  34. export const store = configureStore({
  35. reducer: {
  36. pokemons: persistedReducer,
  37. },
  38. middleware: (getDefaultMiddleware) =>
  39. getDefaultMiddleware({
  40. serializableCheck: {
  41. ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
  42. },
  43. }),
  44. });
  45. /**
  46. * The Redux persistor for persisting store state.
  47. * @const persistor
  48. */
  49. export const persistor = persistStore(store);