51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
// // store.ts
|
|
// import { configureStore } from "@reduxjs/toolkit";
|
|
// import userReducer from "./userSlice"; // adjust the path
|
|
|
|
// export const store = configureStore({
|
|
// reducer: {
|
|
// user: userReducer, // register user slice here
|
|
// },
|
|
// });
|
|
|
|
// // ✅ Types for TypeScript
|
|
// export type RootState = ReturnType<typeof store.getState>;
|
|
// export type AppDispatch = typeof store.dispatch;
|
|
|
|
|
|
|
|
import { configureStore, combineReducers } from '@reduxjs/toolkit';
|
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
import { persistReducer, persistStore } from 'redux-persist';
|
|
|
|
// import slices
|
|
import userReducer from './userSlice';
|
|
import notificationReducer from './notificationSlice';
|
|
|
|
// combine reducers
|
|
const rootReducer = combineReducers({
|
|
user: userReducer,
|
|
notifications: notificationReducer,
|
|
});
|
|
|
|
// persist configuration
|
|
const persistConfig = {
|
|
key: 'root',
|
|
storage: AsyncStorage,
|
|
whitelist: ['user', 'notifications'], // persist both slices
|
|
};
|
|
|
|
// wrap root reducer with persistReducer
|
|
const persistedReducer = persistReducer(persistConfig, rootReducer);
|
|
|
|
// configure store
|
|
export const store = configureStore({
|
|
reducer: persistedReducer,
|
|
middleware: (getDefaultMiddleware) =>
|
|
getDefaultMiddleware({
|
|
serializableCheck: false,
|
|
}),
|
|
});
|
|
|
|
export const persistor = persistStore(store);
|