简体   繁体   English

makeStyles 的 Material-UI 问题

[英]Material-UI issue with makeStyles

I have faced the following issue:我遇到了以下问题:

 ...
 var useStyles = makeStyles(function (theme) {
  11 |     var _a;
> 12 |     return createStyles({
  13 |         button: {
 ...

package.json with material-ui deps: package.json和 material-ui deps:

...
"@material-ui/core": "4.9.7",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "^4.0.0-alpha.45",
"@material-ui/pickers": "3.2.8",
"jss": "^10.0.2",
"material-ui": "^0.20.2",
"mdi-material-ui": "^6.2.0",
...

I have no idea what went wrong.我不知道出了什么问题。 Other related answers on StackOverflow didn't helped me. StackOverflow 上的其他相关答案对我没有帮助。 So, I hope you could help me with that issue!所以,我希望你能帮助我解决这个问题! Thanks谢谢

There is no need to use createStyles with makeStyles inside a functional component.无需在功能组件内使用createStylesmakeStyles

  • Classical: withStyles (High order function) + createStyles经典:withStyles(高阶函数)+ createStyles
  • Functional: useStyles (hooks) + makeStyles功能:useStyles(钩子)+ makeStyles
import { makeStyles } from "@material-ui/core/styles";

const useStyles = makeStyles(theme => ({
  button: {
  }
}));

const classes = useStyles();

Refer:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM