47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { configureStore, combineReducers } from "@reduxjs/toolkit";
|
|
import authReducer from "@/features/authSlice";
|
|
import uiReducer from "@/features/uiSlice";
|
|
|
|
import {
|
|
persistStore,
|
|
persistReducer,
|
|
FLUSH,
|
|
REHYDRATE,
|
|
PAUSE,
|
|
PERSIST,
|
|
PURGE,
|
|
REGISTER,
|
|
} from "redux-persist";
|
|
import storage from "redux-persist/lib/storage"; // defaults to localStorage for web
|
|
|
|
const rootReducer = combineReducers({
|
|
auth: authReducer,
|
|
ui: uiReducer,
|
|
});
|
|
|
|
const persistConfig = {
|
|
key: "root",
|
|
storage,
|
|
whitelist: ["auth", "ui"],
|
|
};
|
|
|
|
const persistedReducer = persistReducer(persistConfig, rootReducer);
|
|
|
|
export const store = configureStore({
|
|
reducer: persistedReducer,
|
|
devTools: process.env.NODE_ENV === "development",
|
|
middleware: (getDefaultMiddleware) =>
|
|
getDefaultMiddleware({
|
|
serializableCheck: {
|
|
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
|
|
},
|
|
}),
|
|
});
|
|
|
|
export const persistor = persistStore(store);
|
|
|
|
// Infer the `RootState` and `AppDispatch` types from the store itself
|
|
export type RootState = ReturnType<typeof store.getState>;
|
|
// Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState}
|
|
export type AppDispatch = typeof store.dispatch;
|