From e2f682b858cec28d9098b012b4a5917d3708629c Mon Sep 17 00:00:00 2001 From: zikaeroh <48577114+zikaeroh@users.noreply.github.com> Date: Fri, 11 Sep 2020 14:30:23 -0700 Subject: [PATCH] Memoize theme toggle function --- frontend/src/index.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/src/index.tsx b/frontend/src/index.tsx index fcb553e..320592b 100644 --- a/frontend/src/index.tsx +++ b/frontend/src/index.tsx @@ -33,13 +33,13 @@ function useTheme() { }) ); - const toggleTheme = () => { + const toggleTheme = React.useMemo(() => { if (themeName === 'light') { - setThemeName('dark'); + return () => setThemeName('dark'); } else { - setThemeName('light'); + return () => setThemeName('light'); } - }; + }, [themeName, setThemeName]); return { theme, toggleTheme, isDark: themeName === 'dark' }; }