如何解决解构道具和状态导致 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 举报,一经查实,本站将立刻删除。