Skip to content

Instantly share code, notes, and snippets.

@Momotoculteur
Created December 4, 2021 19:32
Show Gist options
  • Save Momotoculteur/7c0205bd81e6f372e12c467dc5e55d24 to your computer and use it in GitHub Desktop.
Save Momotoculteur/7c0205bd81e6f372e12c467dc5e55d24 to your computer and use it in GitHub Desktop.
custom dark light theme switch system for react app build with material ui design
import Stack from '@material-ui/core/Stack';
import Button from '@material-ui/core/Button';
import { Switch, Typography } from '@material-ui/core';
import { Box } from '@material-ui/system';
import { useContext } from 'react';
import ThemeContext from '../Theme/ThemeContext';
function ContentApp() {
const { isDark, toggleTheme } = useContext(ThemeContext);
return (
<Box>
<Stack spacing={2} direction="row">
<Button variant="text">Text</Button>
<Button variant="contained" onClick={toggleTheme}>Change Theme button</Button>
<Button variant="outlined">Outlined</Button>
</Stack>
<Typography>
<Switch checked={isDark} onChange={toggleTheme} />
Change Theme switch
</Typography>
</Box>
)
}
export default ContentApp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment