问题
Where should I put following line to get my component ready?
const classes = useStyles();
Try to use Material-UI
MenuList
component, but need to use in my existing MainPage
code, what is slightly different from Material-UI
code example.
回答1:
I think for class properties, the syntax should be something like
class Foo {
classes = useStyle();
}
回答2:
Could you try to call it inside render lifecycle If i'm not wrong, u can't create const directly inside class, the order should be class > function > const or let var Or you can try to put it inside constructor
Constructor(props) {
super(props)
this.classes = useStyles()
}
Or you can do it like seanplwong suggest
回答3:
constants are not supported at class level.
You have two options.
- move the constants out of class and refer then.
- Use static properties
This thread has some more information. Declaring static constants in ES6 classes?
来源:https://stackoverflow.com/questions/57742857/const-can-not-be-defined-in-class-in-node