I write React class constructor use es6, but there is a red highlight error in webstorm9 editor here is the part of code:
class AssetSelectDialog extends React.Component {
static propTypes = {
data: React.PropTypes.any,
pageState: React.PropTypes.string,
pageStatus: React.PropTypes.string,
handleCancel: React.PropTypes.func,
handleSave: React.PropTypes.func
};
constructor(props) {
super(props);
this.PAGE_STATUS = {
SHOW: 'SHOW',
SELECT: 'SELECT'
};
this.state = {
data: this.props.data || {},
pageState: this.props.pageState || CONST.STATUS.EDIT,
pageStatus: this.props.pageStatus || this.PAGE_STATUS.SHOW
};
}
there error was found in super(props);
and the message is Superclass constructor invocation should be in constructor body
.
the code is run ok in babel., how can I fixed it?
It is required if the parameterized constructor (a constructor that takes arguments) of the superclass has to be called from the subclass constructor. The parameterized super() must always be the first statement in the body of the constructor of the subclass, otherwise, we get a compilation error.
Java requires that if you call this() or super() in a constructor, it must be the first statement.
this or super Must Be the First Statement in the Constructor. Whenever we call a constructor, it must call the constructor of its base class. In addition, you can call another constructor within the class. Java enforces this rule by making the first call in a constructor be to this or super.
If the super class does not have a no-argument constructor, you will get a compile-time error. Object does have such a constructor, so if Object is the only superclass, there is no problem.
It's a bug in WebStorm, WEB-14601 is fixed in WebStorm 10.0.4
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