Skip to content

Instantly share code, notes, and snippets.

@mohsentaleb
Created April 12, 2020 19:19
Show Gist options
  • Save mohsentaleb/200a06335cd7a0fad387008eb69ab723 to your computer and use it in GitHub Desktop.
Save mohsentaleb/200a06335cd7a0fad387008eb69ab723 to your computer and use it in GitHub Desktop.
New Custom Styles (classes) and Theme variable in Class Body
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