Created
April 12, 2020 19:19
-
-
Save mohsentaleb/200a06335cd7a0fad387008eb69ab723 to your computer and use it in GitHub Desktop.
New Custom Styles (classes) and Theme variable in Class Body
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Box } from "@material-ui/core" | |
import { withStyles } from "@material-ui/core/styles" | |
const styles = theme => ({ | |
myCustomClass: { | |
color: theme.palette.tertiary.dark | |
} | |
}) | |
class myComponent extends Component { | |
render() { | |
const { classes, theme } = this.props | |
// A component decorated with withStyles(styles) gets a special `classes` prop injected, | |
// Also we have passed `{ withTheme: true }` option to have the theme variable in class body | |
return <Box className={classes.myCustomClass} padding={theme.spacing(4)} /> | |
} | |
} | |
export default withStyles(styles, { withTheme: true })(myComponent) | |
// if you have other HOCs: | |
// export default withStyles(styles, { withTheme: true })( | |
// withRouter(connect(mapStateToProps)(myComponent)) | |
// ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment