Skip to content

Instantly share code, notes, and snippets.

@celeroncoder
Last active April 8, 2022 16:59
Show Gist options
  • Save celeroncoder/0db4e5310b8ec4e93c5c85b0a71e9cab to your computer and use it in GitHub Desktop.
Save celeroncoder/0db4e5310b8ec4e93c5c85b0a71e9cab to your computer and use it in GitHub Desktop.
Mantine Setup App Component
import {
MantineProvider,
ColorScheme,
ColorSchemeProvider,
} from "@mantine/core";
import { useHotkeys, useLocalStorage, useColorScheme } from "@mantine/hooks";
import MainComponent from "./MainComponent";
function App() {
const preferredColorScheme = useColorScheme();
const [colorScheme, setColorScheme] = useLocalStorage<ColorScheme>({
key: "mantine-color-scheme",
defaultValue: preferredColorScheme,
});
const toggleColorScheme = (value?: ColorScheme) =>
setColorScheme(value || (colorScheme === "dark" ? "light" : "dark"));
useHotkeys([["mod+J", () => toggleColorScheme()]]);
return (
<ColorSchemeProvider
colorScheme={colorScheme}
toggleColorScheme={toggleColorScheme}
>
<MantineProvider theme={{ colorScheme }}>
<MainComponent />
</MantineProvider>
</ColorSchemeProvider>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment