29 lines
755 B
TypeScript
29 lines
755 B
TypeScript
// store/index.ts
|
|
import { configureStore, combineReducers } from '@reduxjs/toolkit';
|
|
import { persistStore, persistReducer } from 'redux-persist';
|
|
import storage from 'redux-persist/lib/storage'; // defaults to localStorage for web
|
|
import authReducer from './authSlice';
|
|
|
|
const rootReducer = combineReducers({
|
|
auth: authReducer,
|
|
});
|
|
|
|
const persistConfig = {
|
|
key: 'root',
|
|
storage,
|
|
whitelist: ['auth'], // only auth will be persisted
|
|
};
|
|
|
|
const persistedReducer = persistReducer(persistConfig, rootReducer);
|
|
|
|
const store = configureStore({
|
|
reducer: persistedReducer,
|
|
});
|
|
|
|
const persistor = persistStore(store);
|
|
|
|
export type RootState = ReturnType<typeof rootReducer>;
|
|
export type AppDispatch = typeof store.dispatch;
|
|
|
|
export { store, persistor };
|