From 53392ced6c35095093ac1b097caa57d02faf28f8 Mon Sep 17 00:00:00 2001 From: Mudit Mahajan Date: Wed, 10 Apr 2024 17:09:16 +0530 Subject: [PATCH] Refactor layout component to include PersistGate for Redux state persistence and improve code readability --- src/ui/app/layout.tsx | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/ui/app/layout.tsx b/src/ui/app/layout.tsx index af2d26b9..526797e1 100644 --- a/src/ui/app/layout.tsx +++ b/src/ui/app/layout.tsx @@ -6,12 +6,12 @@ import { Inter } from "next/font/google"; import { SnackbarProvider } from "notistack"; import { useRef } from "react"; import { Provider } from "react-redux"; +import { PersistGate } from "redux-persist/es/integration/react"; +import persistStore from "redux-persist/es/persistStore"; +import { Persistor } from "redux-persist/es/types"; import ThemeRegistry from "./ThemeRegistry"; import Navbar from "./components/navbar"; import "./globals.css"; -import { PersistGate } from "redux-persist/es/integration/react"; -import persistStore from "redux-persist/es/persistStore"; -import { Backdrop, CircularProgress } from "@mui/material"; const inter = Inter({ subsets: ["latin"] }); @@ -21,12 +21,16 @@ export default function RootLayout({ children: React.ReactNode; }) { const storeRef = useRef(); + const persistorRef = useRef(); if (!storeRef.current) { // Create the store instance the first time this renders storeRef.current = makeStore(); } - const persistor = persistStore(storeRef.current); + if (!persistorRef.current) { + // Create the persistor instance the first time this renders + persistorRef.current = persistStore(storeRef.current); + } return ( @@ -44,14 +48,7 @@ export default function RootLayout({ preventDuplicate > - - - - } - persistor={persistor} - > +