Skip to content

Instantly share code, notes, and snippets.

@uds5501
Last active May 6, 2020 17:44
Show Gist options
  • Save uds5501/0cee43e995c0bc85fefabd537a4f5903 to your computer and use it in GitHub Desktop.
Save uds5501/0cee43e995c0bc85fefabd537a4f5903 to your computer and use it in GitHub Desktop.
Theme switcher
import { createMuiTheme, ThemeProvider } from "@material-ui/core/styles";
import React, { useState } from "react";
import Switch from "@material-ui/core/Switch";
export default function Dashboard() {
const [darkState, setDarkState] = useState(false);
const palletType = darkState ? "dark" : "light";
const darkTheme = createMuiTheme({
palette: {
type: palletType,
}
});
const handleThemeChange = () => {
setDarkState(!darkState);
};
return (
<ThemeProvider theme={darkTheme}>
<div> Sample Text </div>
<Switch checked={darkState} onChange={handleThemeChange} />
</ThemeProvider>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment