我开始编码的时候遇到了一些问题 VScode </跨度> 与React。
根据ReactJS文档,
声明默认道具使用函数和ES6类,defaultProps被定义为…的属性{
构造函数(道具){ 超级(道具); this.state = {records:props.data}; }
Records.defaultProps = { 记录: []};
我在输入此代码时出现此错误 VScode </跨度> 。
[js]‘;’预期
我的.defaultProps代码是错误的还是这个 VScode </跨度> 事情?谢谢! …
如果要在React组件类中定义defaultProp,则需要使用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中,你可能有一个用户设置来终止 ; 在每一行
;