Const can not be defined in class in Node?

北战南征 提交于 2020-01-06 05:43:31

问题


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.

  1. move the constants out of class and refer then.
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!