import { PaletteMode } from '@mui/material'; import * as React from 'react'; interface State { mode: PaletteMode; toggleMode: () => void; } const AppContext = React.createContext(undefined); export const useAppContext = (): State => { const context = React.useContext(AppContext); if (!context) { throw new Error('Please include a `import { AppContextProvider } from "./context"` before using this hook'); } return context; }; export const AppContextProvider: FCWithChildren = ({ children }) => { // light/dark mode const [mode, setMode] = React.useState('dark'); const value = React.useMemo( () => ({ mode, toggleMode: () => setMode((prevMode) => (prevMode !== 'light' ? 'light' : 'dark')), }), [mode], ); return {children}; };