错误:
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 defaultMaterial-UI
theme is applied to the re-exportedmakeStyles
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/