Memo the context

This commit is contained in:
Manav Rathi 2024-11-26 18:01:33 +05:30
parent 0e4522c287
commit e5a43e9738
No known key found for this signature in database

View File

@ -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<AppProps> = ({ 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;