javascript - Material -UI 错误 : Object is not a function within makeStyles?

标签 javascript reactjs material-ui

错误:

TypeError: Object(...) is not a function
  13 | import { connect } from 'react-redux';
  14 | 
  15 | 
> 16 | const useStyles = makeStyles(theme => ({
  17 |     ...theme
  18 | }));
  19 | 

代码:

const useStyles = makeStyles(theme => ({
    ...theme
}));

为什么会出现上述错误?
一切正常,但突然我收到了这个错误,可能是在我更新 npm npm -g update 之后,但我不确定。

有人可以帮忙吗?

编辑:这就是我使用 useStyles 的方式:

const classes = useStyles();

然后我使用这些类来设计我的元素,如下所示:

<Button className={classes.button} />

classes.button 从全局主题中获取按钮规则并使用它来设置按钮的样式

最佳答案

To remove the need to systematically supply a theme,
the default Material-UI theme is applied to the re-exported makeStyles modules.

// Re-export with a default theme
import { makeStyles } from '@material-ui/core/styles';

// Original module with no default theme
import { makeStyles } from '@material-ui/styles';

但也要小心“错误”的导入。

// for example, this is wrong
import { makeStyles } from '@material-ui/core/styles/makeStyles';

就像什么@Code Eagle ,这里,已经陷入了。调试此类错误可能会很痛苦:)
这里有一篇关于此的好文章 Material-UI basics .

关于javascript - Material -UI 错误 : Object is not a function within makeStyles?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63239277/

相关文章:

javascript - Ember 数据 JSONAPIAdapter : fetch nested resources

javascript - 如何使用 ReactJS 获取总列​​数?

javascript - 在 ReactJs 组件中的 props 上运行函数

typescript - 如何使用 Material UI 选择器主题扩展 Material UI 3 主题 Typescript 定义

reactjs - 如何解决 TypeScript 错误 "Type ' Dayjs' 缺少类型 'Date' 的属性“当将 Day.js 与 Material-UI DatePicker 一起使用时?

javascript - eslint "indent"规则的第一个参数是什么

javascript - 一页上有几个倒数计时器

javascript - 用字符串句子将每个单词与元素分开,但有一些跨度

javascript - 使用新的 React hook useContext 的正确方法是什么?

reactjs - 如何通过传递 startIcon Prop 在 Material ui 按钮中放置图像