From f95ff6049f89a335c1337ed1528476b66c957e8a Mon Sep 17 00:00:00 2001 From: "Tom (plebeius.eth)" Date: Mon, 26 Aug 2024 12:31:15 +0200 Subject: [PATCH] memoize initial theme --- src/app.tsx | 1 - src/hooks/use-initial-theme.ts | 8 +++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/app.tsx b/src/app.tsx index dd8a07f4..f305c045 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -18,7 +18,6 @@ import SubplebbitStats from './components/subplebbit-stats'; import TopBar from './components/topbar'; import { timeFilterNames } from './hooks/use-time-filter'; import useTheme from './hooks/use-theme'; -import useInitialTheme from './hooks/use-initial-theme'; const BoardLayout = () => { const { accountCommentIndex, subplebbitAddress, timeFilterName } = useParams(); diff --git a/src/hooks/use-initial-theme.ts b/src/hooks/use-initial-theme.ts index af0978d9..0af95177 100644 --- a/src/hooks/use-initial-theme.ts +++ b/src/hooks/use-initial-theme.ts @@ -1,4 +1,4 @@ -import { useEffect } from 'react'; +import { useMemo } from 'react'; import { useLocation, useParams } from 'react-router-dom'; import useThemeStore from '../stores/use-theme-store'; import useDefaultSubplebbits from './use-default-subplebbits'; @@ -18,9 +18,7 @@ const useInitialTheme = () => { const isInSubscriptionsView = isSubscriptionsView(location.pathname, params); const isInPendingPostView = isPendingPostView(location.pathname, params); - let initialTheme = 'yotsuba'; - - useEffect(() => { + const initialTheme = useMemo(() => { let theme = 'yotsuba'; if (isInPendingPostView) { @@ -38,7 +36,7 @@ const useInitialTheme = () => { } } - initialTheme = theme; + return theme; }, [isInPendingPostView, isInAllView, isInSubscriptionsView, isInHomeView, isInNotFoundView, subplebbitAddress, getTheme, currentTheme, subplebbits]); return initialTheme;