store.ts 976 B

123456789101112131415161718192021222324252627282930313233343536
  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 rootReducer from './root.ts';
  14. import { useDispatch } from 'react-redux';
  15. const persistConfig = {
  16. key: 'persist_root',
  17. version: 2,
  18. storage: storage,
  19. };
  20. const persistedReducer = persistReducer(persistConfig, rootReducer);
  21. export const store = configureStore({
  22. reducer: persistedReducer,
  23. middleware: (getDefaultMiddleware) =>
  24. getDefaultMiddleware({
  25. serializableCheck: {
  26. ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
  27. },
  28. }),
  29. });
  30. export type RootState = ReturnType<typeof rootReducer>;
  31. export type AppDispatch = typeof store.dispatch;
  32. export const persistor = persistStore(store);
  33. export const useAppDispatch = () => useDispatch<AppDispatch>();