You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

useToggleColorMode.js 697B

12345678910111213141516171819202122232425262728293031
  1. import { useState, useMemo } from 'react';
  2. import { createTheme } from '@mui/material/styles';
  3. import {
  4. authScopeSetHelper,
  5. authScopeStringGetHelper,
  6. } from '../util/helpers/authScopeHelpers';
  7. const useToggleColorMode = () => {
  8. const currentColorMode = authScopeStringGetHelper('colorMode') || 'light';
  9. const [mode, setMode] = useState(currentColorMode);
  10. const toggleColorMode = () => {
  11. const nextMode = mode === 'light' ? 'dark' : 'light';
  12. setMode(nextMode);
  13. authScopeSetHelper('colorMode', nextMode);
  14. };
  15. const theme = useMemo(
  16. () =>
  17. createTheme({
  18. palette: {
  19. mode,
  20. },
  21. }),
  22. [mode]
  23. );
  24. return [toggleColorMode, theme];
  25. };
  26. export default useToggleColorMode;