How to store the value of the dark mode in localStorage?
can I even do it in this way?
can you guys give me ideas on how?
thank you cheers,
function App() {
const [darkState, setDarkState] = useState("");
const palletType = darkState ? "dark" : "light";
const mainPrimaryColor = darkState ? blue[400] : blue[800];
const mainSecondaryColor = darkState ? grey[800] : grey[100];
const darkTheme = createMuiTheme({
palette: {
type: palletType,
primary: {
main: mainPrimaryColor,
},
secondary: {
main: mainSecondaryColor,
},
},
});
function handleThemeChange() {
setDarkState(!darkState);
}
return (
<ThemeProvider theme={darkTheme}>
<IconButton onClick={handleThemeChange()}>
<Switch checked={darkState} />
</IconButton>
</ThemeProvider>
);
}