![](/img/trans.png)
[英]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.