Reactjs 在React+中提取样式;材料界面
我使用的是React+材质界面。我想将每个组件中定义的样式提取到一个公共文件中 如果将以下内容放在一个文件中,则每个文件都可以正常工作:-Reactjs 在React+中提取样式;材料界面,reactjs,material-ui,Reactjs,Material Ui,我使用的是React+材质界面。我想将每个组件中定义的样式提取到一个公共文件中 如果将以下内容放在一个文件中,则每个文件都可以正常工作:- import { withStyles } from '@material-ui/core/styles'; ... const styles = theme => ({ createButton: { [theme.breakpoints.up('md')]: { borderRadius: '10p
import { withStyles } from '@material-ui/core/styles';
...
const styles = theme => ({
createButton: {
[theme.breakpoints.up('md')]: {
borderRadius: '10px',
display: 'block',
margin: '0 auto',
marginTop: '10px',
marginBottom: '10px',
width: '360px',
},
[theme.breakpoints.down('sm')]: {
borderRadius: '0px',
bottom: '0px',
position: 'relative',
width: '100%',
height: '60px',
fontSize: '20px',
},
backgroundColor: theme.palette.secondary.main,
color: 'white',
'&:hover': {
backgroundColor: theme.palette.secondary.main,
},
}
});
...
class Home extends Component {
...
<Button className={this.props.classes.createButton}>Hello</Button>
...
}
export default (withStyles(styles)(Home));
然后,当我
import { styles } from './somewhere/common';
createButton样式不再工作
它提到
Attempted import error: 'styles' is not exported from './somewhere/common'.
您需要从
'./somewhere/common'
导出样式
,将其添加到文件末尾:
export default styles;
并使用以下方式导入:
import styles from './somewhere/common'
您需要从
'./somewhere/common'
导出样式
,将其添加到文件末尾:
export default styles;
并使用以下方式导入:
import styles from './somewhere/common'
您可以将样式作为道具传递给所有其他组件。您可以将样式作为道具传递给所有其他组件。