Javascript TypeError:无法创建数据属性~React~ESLint
在某些React组件上使用ESLint时,我遇到一个类型错误,它会终止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
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
的每个文件中都会重复该错误,但找不到原因的解释。项目处于React15.6.2
中,我想说您的问题可能是重复属性1:
MyComponent.defaultProps = {
property1: null, // remove this one
loading: true,
property1: [], // or this one
property2: null
}
调试lint规则的另一个很好的方法是设置ignore rule标志->查看规则的名称,并尝试弄清楚它在做什么(有些规则限制太多,可能不适合您的项目)