Here is my React.js component definition:
class ExampleComponent1 extends React.Component {
constructor() {
super();
}
}
When webpack this with babel loader, everything would be fine. But then I change the constructor declare to arrow function:
class ExampleComponent1 extends React.Component {
constructor = () => {
super();
}
}
webpack build failed:
Module build failed: SyntaxError:....: 'super' outside of function or class (8:4)
I don't know why this happened, constructor can't declare as arrow function?
In ES6, functions can be maked using arrow but only if they are procedural or lambda functions !
Into class declarations, you are only allowed to use the standard ES6 syntax :
class ExampleComponent1 extends React.Component {
constructor() {
super();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With