Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript TypeError:无法创建数据属性~React~ESLint_Javascript_Reactjs_Eslint_Static Analysis_Static Code Analysis - Fatal编程技术网

Javascript TypeError:无法创建数据属性~React~ESLint

Javascript TypeError:无法创建数据属性~React~ESLint,javascript,reactjs,eslint,static-analysis,static-code-analysis,Javascript,Reactjs,Eslint,Static Analysis,Static Code Analysis,在某些React组件上使用ESLint时,我遇到一个类型错误,它会终止ESLint,并显示消息TypeError:cannotcreatedata属性。将路径/TO/MY/REACT/COMPONENT/mycomponent.js.jsx:54挂接时发生 代码如下所示: class MyComponentextends React.Component { ... // Some component's logic. } // MyComponent.defaultProps is the

在某些React组件上使用ESLint时,我遇到一个类型错误,它会终止ESLint,并显示消息
TypeError:cannotcreatedata属性。将路径/TO/MY/REACT/COMPONENT/mycomponent.js.jsx:54挂接时发生

代码如下所示:

class MyComponentextends React.Component {
  ... // Some component's logic.
}
// MyComponent.defaultProps is the line 54 to which the errors points out.
MyComponent.defaultProps = {
  property1: null,
  loading: true,
  property1: [],
  property2: null
}

在声明了
任何组件.defaultProps
的每个文件中都会重复该错误,但找不到原因的解释。项目处于React
15.6.2

中,我想说您的问题可能是重复属性1:

MyComponent.defaultProps = {
  property1: null, // remove this one
  loading: true,
  property1: [], // or this one
  property2: null
}
调试lint规则的另一个很好的方法是设置ignore rule标志->查看规则的名称,并尝试弄清楚它在做什么(有些规则限制太多,可能不适合您的项目)