当我开始使用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?谢谢!
1 回答
如果要在React组件类中定义defaultProp,则需要使用Static关键字来定义它
或者声明它
同样在你的VSCODE中,你可能有一个用户设置,每行都有一个终止
;