1

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.

enter image description here

János
  • 32,867
  • 38
  • 193
  • 353

3 Answers3

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

Kaslie
  • 543
  • 2
  • 9
  • Ahh render lifecycle... I'm forgetting the important React stuff and falsely blaming my limited knowledge of Javascript. Thank you for your answer! – TelamonAegisthus Oct 14 '20 at 09:42
2

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?

indolentdeveloper
  • 1,253
  • 1
  • 11
  • 15
1

I think for class properties, the syntax should be something like

class Foo {
  classes = useStyle();
}
seanplwong
  • 1,051
  • 5
  • 14