another step for constructing base project
This commit is contained in:
@@ -1,17 +1,14 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useAppStore } from '../store';
|
||||
import { useColorScheme } from '@mui/material/styles';
|
||||
|
||||
/**
|
||||
* Returns event handler to toggle Dark/Light modes
|
||||
* @returns {function} calling this event toggles dark/light mode
|
||||
* Returns an event handler that toggles dark/light mode via MUI's CSS-vars system.
|
||||
* Calling the returned function sets data-mui-color-scheme on <html> — no React
|
||||
* re-render happens outside the component that calls this hook.
|
||||
*/
|
||||
export function useEventSwitchDarkMode() {
|
||||
const [state, dispatch] = useAppStore();
|
||||
|
||||
const { mode, setMode } = useColorScheme();
|
||||
return useCallback(() => {
|
||||
dispatch({
|
||||
type: 'DARK_MODE',
|
||||
payload: !state.darkMode,
|
||||
});
|
||||
}, [state, dispatch]);
|
||||
setMode(mode === 'dark' ? 'light' : 'dark');
|
||||
}, [mode, setMode]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user