我已升级到babel
版本6,并且已将其"es2015", "react", "stage-0"
用作预设。我正在react
使用es6语法。
在升级之前,一切工作正常。升级后,我开始在对父构造函数进行超级调用的地方获得异常。
例如下面的类:
class childForm extends ParentForm {
constructor(props, context) {
console.log("this get printed.");
super(props, context);
console.log("this is not printed");
}
...
}
class ParentForm extends React.Component {
constructor(props, context) {
console.log("this is printed");
super(props, context);
console.log("this is printed too");
}
...
}
class AnotherComponent extends React.Component {
constructor(props) {
super(props);
this.state = {};
myService.findById(this.props.params.id).then(result => {
this.setState({result: result});
}).catch(err => {
/**** Error is catched here ******/
console.log(err);
});
}
render(){
return <div>{this.state.result && <ChildForm/>}</div>
}
}
我在控制台上收到以下错误:
TypeError: (0 , _typeof3.default) is not a function(…)
ReactCompositeComponent.js?cd59:443 Uncaught (in promise) TypeError: Cannot read property 'context' of null(…)
引发错误的React函数是以下函数。在处引发的例外ReactCompositeComponentMixin.updateComponent
updateComponent: function (transaction, prevParentElement, nextParentElement, prevUnmaskedContext, nextUnmaskedContext) {
var inst = this._instance;
var nextContext = this._context === nextUnmaskedContext ? inst.context : this._processContext(nextUnmaskedContext);
....
如果我将父类的所有功能都带到子类,则它可以按预期工作。有没有人遇到过类似的问题?
还可以使用某些库或插件进行响应来获得更好的异常消息吗?
安装[email protected]应该可以解决问题。签出问题https://phabricator.babeljs.io/T6644
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句