Files

51 lines
1.2 KiB
TypeScript
Raw Permalink Normal View History

2024-06-20 14:07:33 -07:00
import { configureStore, combineReducers } from "@reduxjs/toolkit";
2026-02-12 18:30:15 +00:00
import authReducer from "@/Features/Auth/authSlice";
import uiReducer from "@/Features/UI/uiSlice";
2024-06-20 14:07:33 -07:00
import storage from "redux-persist/lib/storage";
2026-02-12 18:30:15 +00:00
import {
persistReducer,
persistStore,
createTransform,
PERSIST,
REHYDRATE,
} from "redux-persist";
const authTransform = createTransform(
2026-02-12 18:30:15 +00:00
(inboundState: Record<string, unknown>) => {
const { profileImage, ...rest } = inboundState;
return rest;
},
2026-02-12 18:30:15 +00:00
undefined,
{ whitelist: ["auth"] }
);
2024-06-20 14:07:33 -07:00
const persistConfig = {
key: "root",
storage,
2025-12-04 10:31:45 -06:00
whitelist: ["auth", "ui"],
transforms: [authTransform],
2024-06-20 14:07:33 -07:00
};
const rootReducer = combineReducers({
auth: authReducer,
ui: uiReducer,
});
2024-06-20 14:07:33 -07:00
2026-02-12 18:30:15 +00:00
// @ts-expect-error - redux-persist types don't align perfectly with redux-toolkit
2024-06-20 14:07:33 -07:00
const persistedReducer = persistReducer(persistConfig, rootReducer);
export const store = configureStore({
reducer: persistedReducer,
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
serializableCheck: {
2026-02-12 18:30:15 +00:00
ignoredActions: [PERSIST, REHYDRATE, "persist/REGISTER"],
},
}),
2024-06-20 14:07:33 -07:00
});
2026-02-12 18:30:15 +00:00
export type RootState = ReturnType<typeof rootReducer>;
export type AppDispatch = typeof store.dispatch;
2024-06-20 14:07:33 -07:00
export const persistor = persistStore(store);
2024-09-27 12:13:39 +08:00
export default store;