[英]Strange Unresolved dependencies to 'vscode' when wrapping monaco-editor and monaco-languageclient as a react component
[英]React with VScode Editor
我开始使用React在VScode上编码时遇到一些问题。
根据ReactJS文档,
声明默认属性使用函数和ES6类,defaultProps被定义为组件本身的属性:
class Greeting extends React.Component {
// ...
}
Greeting.defaultProps = {
name: 'Mary'
};
我试图遵循,这是我的代码:
class Records extends React.Component {
constructor(props) {
super (props);
this.state = {records: props.data};
}
Records.defaultProps = {
records: []
};
在VScode中键入此代码时出现此错误。
[js] ';' expected
我的.defaultProps代码是错误的还是这是VScode? 谢谢!
如果要在React组件类中定义defaultProps,则需要使用Static关键字进行定义,例如
class Records extends React.Component {
constructor(props) {
super (props);
this.state = {records: props.data}
}
static defaultProps = {
records: []
};
否则就这样声明
class Records extends React.Component {
constructor(props) {
super (props);
this.state = {records: props.data};
}
}
Records.defaultProps = {
records: [];
};
同样,在您的VSCODE中,您可能具有用户设置来终止;
在每一行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.