【问题标题】:React js: Converting Material-UI functional code into class component throws typerrorReact js:将Material-UI功能代码转换为类组件抛出typeerror
【发布时间】:2020-12-02 23:18:07
【问题描述】:

所以我使用的是材料 ui 登录页面代码,它是一个功能组件,因此根据我的要求,我需要将其转换为类组件。 但将其转换为类组件会引发错误:“无法分配给对象 '#' 的只读属性 'classes'”

我通过将 app.js 文件包装在其中,将 MiuiThemeProvider 全局传递到 index.js 文件中的 DOM 树中。 我已经小心地移除了所有的钩子,比如用 withStyles 替换 makeStyles。

现在在下面共享的代码沙箱链接中,您可以看到我的类组件,它显示错误(类型错误:无法分配给对象“#”的只读属性“类”)

原material-UI功能组件代码运行正常,但转换为类组件时抛出上述错误

包含所有文件和依赖项的代码沙盒链接https://codesandbox.io/s/magical-goodall-rzdg9?file=/src/App.js

【问题讨论】:

    标签: javascript reactjs authentication material-ui material-design


    【解决方案1】:

    你使用了两次withStyleswithStyles是HOC,请查看Doc

    您需要从 useStyles 中删除 withStyles

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-29
      • 2020-02-26
      • 2021-09-16
      • 2020-06-23
      • 2019-10-19
      • 2020-06-04
      • 2020-07-11
      • 1970-01-01
      相关资源
      最近更新 更多