这是我的eslintrc。它抱怨
let state = {dataObjects: insurances }
不正确。
我该怎么做才能解决这个问题?否则代码运行没有错误。
.eslintrc
{
"extends": "airbnb",
"env": {
"es6": true
},
"parserOptions": {
"sourceType": "module"
}
}
TextablesScreen
12 class TextablesScreen extends React.PureComponent {
13 /* ***********************************************************
14 * STEP 1
15 * This is an array of objects with the properties you desire
16 * Usually this should come from Redux mapStateToProps
17 ************************************************************ */
>> 18 let state = {
19 dataObjects: insurances
20 }
答案 0 :(得分:3)
在React中,this.state
应被视为不可变。使用let
表示状态毫无意义,而应将其添加为类属性:
class TextablesScreen extends React.PureComponent {
state = {
dataObjects: insurances
}
/* ... */
如果需要props
填充默认状态,请在构造函数中设置状态:
constructor(props) {
super(props)
this.state = ...
}