【问题标题】:TypeError: Cannot read property 'spacing' of undefinedTypeError:无法读取未定义的属性“间距”
【发布时间】:2020-04-21 16:22:06
【问题描述】:

使用 react 和 material UI 时出现以下错误

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

代码如下:

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

并且它是由

渲染的
  const classes = useStyles();

【问题讨论】:

    标签: reactjs material-ui


    【解决方案1】:

    我明白了,我把样式移到钩子里并改变了

    export default withStyles(useStyles)(Hookname);
    

    export default Hookname;
    

    并添加了

    const useStyles = makeStyles(theme => ({
    

    而不是

    const useStyles = theme => ({
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-24
      • 2019-08-19
      相关资源
      最近更新 更多