我正在尝试使用material-ui-next组件,我只是在index.js中复制了FullWidthGrid示例,我有很多错误......
这是我的index.js
import React from 'react';
import ReactDom from 'react-dom';
import PropTypes from 'prop-types';
import { withStyles } from 'material-ui/styles';
import Paper from 'material-ui/Paper';
import Grid from 'material-ui/Grid';
const styles = theme => ({
root: {
flexGrow: 1,
},
paper: {
padding: theme.spacing.unit * 2,
textAlign: 'center',
color: theme.palette.text.secondary,
},
});
function FullWidthGrid(props) {
const { classes } = props;
return (
<div className={classes.root}>
<Grid container spacing={24}>
<Grid item xs={12}>
<Paper className={classes.paper}>xs=12</Paper>
</Grid>
<Grid item xs={12} sm={6}>
<Paper className={classes.paper}>xs=12 sm=6</Paper>
</Grid>
<Grid item xs={12} sm={6}>
<Paper className={classes.paper}>xs=12 sm=6</Paper>
</Grid>
<Grid item xs={6} sm={3}>
<Paper className={classes.paper}>xs=6 sm=3</Paper>
</Grid>
<Grid item xs={6} sm={3}>
<Paper className={classes.paper}>xs=6 sm=3</Paper>
</Grid>
<Grid item xs={6} sm={3}>
<Paper className={classes.paper}>xs=6 sm=3</Paper>
</Grid>
<Grid item xs={6} sm={3}>
<Paper className={classes.paper}>xs=6 sm=3</Paper>
</Grid>
</Grid>
</div>
);
}
FullWidthGrid.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(FullWidthGrid);
index.js中的:
class MyApp extends React.Component {
render () {
return (
<div>
<FullWidthGrid />
</div>
)
}
}
ReactDom.render(<MyApp />, document.getElementById('root'));
这是我的控制台中的错误消息:
TypeError:无法读取属性&#39; root&#39;未定义的,包含<div className={classes.root}>
答案 0 :(得分:0)
在index.js中你需要使用样式将类prop传递给FullWidthGrid组件......太糟糕了,示例没有指定它但我认为你可以在他们的GitHub中找到它
示例:
<FullWidthGrid classes={{paper:"paper"}} />