I'm using React and Material-ui, and currently I'm doing something like the code below.
Is there a better way?
For instance, is there a function that allows you to access 'props' within the "styles" jss object below the component that is eventually injected into the component with withStyles() without having to do all this ugly inline styling?
import React from 'react';
import {
MaterialComponentOne,
MaterialComponentTwo,
MaterialComponentThree,
} from '@material-ui/core';
function MyPureComponent(props) {
return (
<MaterialComponentOne
style={
props.type === 'secondary'
? {
css_property: 'css_value1',
}
: {
css_property: 'css_value2',
}
}
className={props.classes.MaterialComponentOne}
position="static"
>
<MaterialComponentTwo>
<MaterialComponentThree
style={
props.type === 'secondary'
? {
css_property: 'css_value1',
}
: {
css_property: 'css_value2',
}
}
variant="title"
className={props.classes.MaterialComponentThree}
>
{props.title}
</MaterialComponentThree>
</MaterialComponentTwo>
</MaterialComponentOne>
);
}
const styles = {
MaterialComponentOne: {
css_property: 'css_value',
css_property: 'css_value',
},
MaterialComponentTwo: {
css_propery: 'css_value',
},
};
export default withTheme()(withStyles(styles)(MyPureComponent));
thanks.