fix(reduxLocalStorageConnect)
This commit is contained in:
parent
bbf975275f
commit
e13cef605a
@ -25,6 +25,7 @@
|
||||
"react-dom": "^18",
|
||||
"react-hook-form": "^7.52.2",
|
||||
"react-redux": "^9.1.2",
|
||||
"redux-persist": "^6.0.0",
|
||||
"sass": "^1.77.8",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
|
@ -4,7 +4,8 @@ import { ThemeProvider } from "@mui/material/styles";
|
||||
import theme from "../theme";
|
||||
import "./globals.scss";
|
||||
import { Provider } from 'react-redux';
|
||||
import store from "@/services/store";
|
||||
import { PersistGate } from 'redux-persist/integration/react';
|
||||
import { store, persistor } from '.././services/store';
|
||||
import AuthGuard from "@/hoc/authGuard/authGuard";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect } from "react";
|
||||
@ -31,9 +32,11 @@ function RootLayout(props: RootLayoutProps): JSX.Element {
|
||||
<html lang="en">
|
||||
<body>
|
||||
<Provider store={store}>
|
||||
<AppRouterCacheProvider>
|
||||
<ThemeProvider theme={theme}>{children}</ThemeProvider>
|
||||
</AppRouterCacheProvider>
|
||||
<PersistGate loading={null} persistor={persistor}>
|
||||
<AppRouterCacheProvider>
|
||||
<ThemeProvider theme={theme}>{children}</ThemeProvider>
|
||||
</AppRouterCacheProvider>
|
||||
</PersistGate>
|
||||
</Provider>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,15 +1,28 @@
|
||||
|
||||
// store/index.ts
|
||||
import { configureStore } from '@reduxjs/toolkit';
|
||||
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 store = configureStore({
|
||||
reducer: {
|
||||
auth: authReducer,
|
||||
},
|
||||
const rootReducer = combineReducers({
|
||||
auth: authReducer,
|
||||
});
|
||||
|
||||
export type RootState = ReturnType<typeof store.getState>;
|
||||
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 default store;
|
||||
export { store, persistor };
|
||||
|
@ -4013,12 +4013,17 @@ redent@^3.0.0:
|
||||
indent-string "^4.0.0"
|
||||
strip-indent "^3.0.0"
|
||||
|
||||
redux-persist@^6.0.0:
|
||||
version "6.0.0"
|
||||
resolved "https://registry.npmjs.org/redux-persist/-/redux-persist-6.0.0.tgz"
|
||||
integrity sha512-71LLMbUq2r02ng2We9S215LtPu3fY0KgaGE0k8WRgl6RkqxtGfl7HUozz1Dftwsb0D/5mZ8dwAaPbtnzfvbEwQ==
|
||||
|
||||
redux-thunk@^3.1.0:
|
||||
version "3.1.0"
|
||||
resolved "https://registry.npmjs.org/redux-thunk/-/redux-thunk-3.1.0.tgz"
|
||||
integrity sha512-NW2r5T6ksUKXCabzhL9z+h206HQw/NJkcLm1GPImRQ8IzfXwRGqjVhKJGauHirT0DAuyy6hjdnMZaRoAcy0Klw==
|
||||
|
||||
redux@^5.0.0, redux@^5.0.1:
|
||||
redux@^5.0.0, redux@^5.0.1, redux@>4.0.0:
|
||||
version "5.0.1"
|
||||
resolved "https://registry.npmjs.org/redux/-/redux-5.0.1.tgz"
|
||||
integrity sha512-M9/ELqF6fy8FwmkpnF0S3YKOqMyoWJ4+CS5Efg2ct3oY9daQvd/Pc71FpGZsVsbl3Cpb+IIcjBDUnnyBdQbq4w==
|
||||
|
Loading…
x
Reference in New Issue
Block a user