解构道具和状态导致 ESlint 中的未使用状态错误

问题描述

我正在使用 Airbnb Eslint 从现有代码中删除错误。我浏览了各种文章和博客,都说要消除 Eslint 的解构错误,我们需要解构 props 和 state。这是现有的代码结构-

class Student extends React.Component{
  constructor(props){
    super(props);
    this.state = {
      Name: null,//line 6
      Age:null
    }
  }
  component.mount(){
    //some code
    {this.props.state.dob} // My props also contains state parameter of 
    object type(dob,tc)
  }

  render (){
    return(
      //some code
      {this.state.Name}
    )
  }
}

export default Student

我尝试在 component.mount 之后使用分配给 const 的 this.props 进行解构,并在渲染分配给 const 的 this.state 之后进行解构。但是在第 6 行未使用的状态字段名称下出现错误。有人能告诉我为什么会发生这种情况,我如何在不添加禁用解构注释的情况下解决它?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...