From e5a43e9738c4fda1089a4edcc7fce0403f54d9a7 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Tue, 26 Nov 2024 18:01:33 +0530 Subject: [PATCH] Memo the context --- web/apps/auth/src/pages/_app.tsx | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/web/apps/auth/src/pages/_app.tsx b/web/apps/auth/src/pages/_app.tsx index 98feccc295..8cd9f1cc33 100644 --- a/web/apps/auth/src/pages/_app.tsx +++ b/web/apps/auth/src/pages/_app.tsx @@ -27,7 +27,7 @@ import { ThemeProvider } from "@mui/material/styles"; import { t } from "i18next"; import type { AppProps } from "next/app"; import { useRouter } from "next/router"; -import React, { useCallback, useEffect, useState } from "react"; +import React, { useCallback, useEffect, useMemo, useState } from "react"; import { AppContext } from "types/context"; import "../../public/css/global.css"; @@ -81,19 +81,20 @@ const App: React.FC = ({ Component, pageProps }) => { }; }, []); - const showNavBar = (show: boolean) => setShowNavBar(show); - const logout = useCallback(() => { void accountLogout().then(() => window.location.replace("/")); }, []); - const appContext = { - logout, - showNavBar, - showMiniDialog, - themeColor, - setThemeColor, - }; + const appContext = useMemo( + () => ({ + logout, + showNavBar: (show: boolean) => setShowNavBar(show), + showMiniDialog, + themeColor, + setThemeColor, + }), + [logout, showMiniDialog, themeColor, setThemeColor], + ); const title = isI18nReady ? t("title_auth") : staticAppTitle;