【发布时间】:2018-05-18 15:11:30
【问题描述】:
所以我有这个组件,我正在尝试以反应方式编写。每个主要容器都作为 React 类组件分开。 现在我知道如何将 withStyles 与一个组件一起使用: 导出默认 withStyles(styles)(MyComponent);
但是当你有两个以上的组件时,你如何使用 withStyles。 这是代码:
class AtmanPage extends Component {
render() {
return (
<AtmanAppBar />
);
}
}
class AtmanAppBar extends Component {
render() {
return (
<div className= {this.props.classes.root}>
<AppBar position="static">
<Toolbar>
<IconButton className= {this.props.classes.menubutton} color="contrast" aria-label="Menu">
<MenuIcon />
</IconButton>
<Typography type="title" color="inherit" className={this.props.classes.flex}>
Title
</Typography>
<Button color="contrast">Login</Button>
</Toolbar>
</AppBar>
</div>
);
}
}
const styles = theme => ({
root: {
marginTop: theme.spacing.unit * 3,
width: '100%',
},
flex: {
flex: 1,
},
menuButton: {
marginLeft: -12,
marginRight: 20,
},
});
export default withStyles(styles) AtmanPage ?;
现在的问号是关于如何通过 AtmanPage 将样式作为道具传递给 AtmanAppBar。
【问题讨论】:
标签: javascript reactjs material-ui