首页 > 解决方案 > TypeError:无法读取未定义的属性“间距”

问题描述

使用 React 和 Material UI 时出现以下错误

TypeError:无法读取未定义的属性“间距”

这是代码:

buttonTeal: {
    margin: theme.spacing(1),
    color:'white',
    backgroundColor: '#009688',

它被渲染

  const classes = useStyles();

标签: reactjsmaterial-ui

解决方案


我明白了,我将样式移到了钩子中并更改了

export default withStyles(useStyles)(Hookname);

export default Hookname;

并添加

const useStyles = makeStyles(theme => ({

而不是

const useStyles = theme => ({

推荐阅读