Memoize theme toggle function

This commit is contained in:
zikaeroh 2020-09-11 14:30:23 -07:00
parent 10a76f961c
commit e2f682b858
1 changed files with 4 additions and 4 deletions

View File

@ -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' };
}