Reactjs 允许“let state={`

Reactjs 允许“let state={`,reactjs,react-native,eslint,eslint-config-airbnb,Reactjs,React Native,Eslint,Eslint Config Airbnb,这是我的eslintrc。它抱怨 let state={dataObjects:insurances}不正确。 我应该怎么做才能解决这个问题?否则代码运行时不会出错 .eslintrc { "extends": "airbnb", "env": { "es6": true }, "parserOptions": { "sourceType": "module" } } TextablesScreen 12 class Textables

这是我的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   }

在React中,
this.state
应被视为不可变。使用
let
for states没有任何意义,您应该将其添加为类属性:

或者,如果您需要
props
来填充默认状态,请在构造函数中设置状态:

constructor(props) {
  super(props)
  this.state = ...
}

在React中,
this.state
应被视为不可变。使用
let
for states没有任何意义,您应该将其添加为类属性:

或者,如果您需要
props
来填充默认状态,请在构造函数中设置状态:

constructor(props) {
  super(props)
  this.state = ...
}

或者使用
this.state=…
设置
constructor
来填充默认状态。如果您需要
props
来填充默认状态。如果您以后想更新它,您应该使用
this.setState
@Sulthan,谢谢您的回复。将其作为答案发布,我会检查它是否正确。:-)或者使用
this.state=
如果你需要
道具
来填充默认状态。如果你以后想更新它,你应该使用
this.setState
@Sulthan,谢谢你的回复。将它作为答案发布,我会检查它是否正确。:-)我认为问题标题应该更改,因为它会误导你。如果有人真的想让let进入他的项目呢:)我想问题标题应该更改,因为它会误导用户。如果有人真的想让let进入他的项目,该怎么办:)