Skip to content

Instantly share code, notes, and snippets.

@up209d
Created March 23, 2018 00:41
Show Gist options
  • Save up209d/8f6187a9e1dd946a3653be594f3a12b9 to your computer and use it in GitHub Desktop.
Save up209d/8f6187a9e1dd946a3653be594f3a12b9 to your computer and use it in GitHub Desktop.
Use props with withStyle in JSS
import React from 'react';
import {
withStyles,
Grid,
CircularProgress
} from 'material-ui';
// const PreloadComponent = props => {
// const { classes,size } = props;
// return (
// <Grid className={classes.container} container justify={'center'} alignItems={'center'}>
// <CircularProgress size={size}/>
// </Grid>
// )
// };
//
// const Preload = props => {
// const { size } = props;
//
// const WithStylesPreloadComponent = withStyles(theme => ({
// container: {
// paddingTop: size*2 || 50,
// paddingBottom: size*2 || 50,
// }
// }),{withTheme: true})(PreloadComponent);
//
// return (
// <WithStylesPreloadComponent {...props}/>
// )
// };
//
// Preload.defaultProps = {
// size: 20
// };
//
// export default Preload;
const PreloadComponent = props => {
const { classes,size } = props;
return (
<Grid className={classes.container} container justify={'center'} alignItems={'center'}>
<CircularProgress size={size}/>
</Grid>
)
};
const StyleWithThemeProps = (props) => {
return withStyles(theme => ({
container: {
paddingTop: props.size*2 || 50,
paddingBottom: props.size*2 || 50,
}
}),{withTheme: true})(PreloadComponent)
};
class PreloadFull extends React.PureComponent {
constructor(props,context) {
super(props);
}
componentWillMount() {
this.StyledPreloadFull = StyleWithThemeProps(this.props);
}
componentWillUpdate(nextProps) {
this.StyledPreloadFull = StyleWithThemeProps(nextProps);
}
render() {
const { StyledPreloadFull,props } = this;
return (
<StyledPreloadFull {...props}/>
);
}
}
PreloadFull.defaultProps = {
size: 20
};
export default PreloadFull;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment