2eee5195cc
* new react and reactdom packages in wallet * new react and reactdom packages in root * new react and reactdom packages in nym connect * new react and reactdom packages in root * update react and reactdom for explorer * react and react-dom upgrade for ts-packages remove unused import fix linting error * use custom FC typing move typings folder * fix type error
35 lines
902 B
TypeScript
35 lines
902 B
TypeScript
import { PaletteMode } from '@mui/material';
|
|
import * as React from 'react';
|
|
|
|
interface State {
|
|
mode: PaletteMode;
|
|
toggleMode: () => void;
|
|
}
|
|
|
|
const AppContext = React.createContext<State | undefined>(undefined);
|
|
|
|
export const useAppContext = (): State => {
|
|
const context = React.useContext<State | undefined>(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<PaletteMode>('dark');
|
|
|
|
const value = React.useMemo<State>(
|
|
() => ({
|
|
mode,
|
|
toggleMode: () => setMode((prevMode) => (prevMode !== 'light' ? 'light' : 'dark')),
|
|
}),
|
|
[mode],
|
|
);
|
|
|
|
return <AppContext.Provider value={value}>{children}</AppContext.Provider>;
|
|
};
|