【发布时间】:2019-05-21 01:44:58
【问题描述】:
Material UI 使用className 进行样式设置。但是如何将样式传递给子反应组件?
以下是我的风格定义。
const styles = createStyles({
root: {
backgroundColor: 'transparent !important',
boxShadow: 'none',
paddingTop: '25px',
color: '#FFFFFF'
},
subComponentStyle: {
...
}
});
我会这样使用:
...
const NavigationBar = (props) => {
const { classes } = props;
return (
<div className={classes.root}>
// Add other code here
<SubComponent ... > // how to pass `classes.subComponentStyle` style here
</div>
)
}
...
export default withStyles(styles)(NavigationBar);
如果SubComponent 组件也使用withStyles 导出。如何传递一些样式来覆盖它自己的样式?
我的SubComponent 导出为:
const styles = createStyles({
...
});
const SubComponent = ({classes}) => {
...
}
export default withStyles(styles)(SubComponent);
如您所见,它有自己的classes。我不想完全覆盖它的类。有没有办法将传入的类与其内部类合并?
【问题讨论】:
标签: reactjs material-ui