mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-16 09:11:38 +00:00
28 lines
671 B
TypeScript
28 lines
671 B
TypeScript
import { ActionKind, useRUAContext } from '../store';
|
|
|
|
const useDarkMode = () => {
|
|
const { state, dispatch } = useRUAContext();
|
|
const { isDark } = state;
|
|
|
|
const toggleDark = () => {
|
|
if (isDark) {
|
|
document.documentElement.classList.remove('dark');
|
|
localStorage.setItem('rua-theme', 'light');
|
|
dispatch({
|
|
type: ActionKind.SETTHEME,
|
|
payload: '',
|
|
});
|
|
} else {
|
|
document.documentElement.classList.add('dark');
|
|
localStorage.setItem('rua-theme', 'dark');
|
|
dispatch({
|
|
type: ActionKind.SETTHEME,
|
|
payload: '',
|
|
});
|
|
}
|
|
};
|
|
|
|
return { isDark, toggleDark };
|
|
};
|
|
export default useDarkMode;
|