notification store and update in local storage
This commit is contained in:
+47
-10
@@ -1,13 +1,50 @@
|
||||
// store.ts
|
||||
import { configureStore } from "@reduxjs/toolkit";
|
||||
import userReducer from "./userSlice"; // adjust the path
|
||||
// // 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
|
||||
},
|
||||
// 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,
|
||||
});
|
||||
|
||||
// ✅ Types for TypeScript
|
||||
export type RootState = ReturnType<typeof store.getState>;
|
||||
export type AppDispatch = typeof store.dispatch;
|
||||
// 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);
|
||||
|
||||
Reference in New Issue
Block a user