Memoize theme toggle function
This commit is contained in:
parent
10a76f961c
commit
e2f682b858
|
@ -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' };
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue