簡體   English   中英

盡管進行了正確的解構(eslint),但仍然存在解構錯誤

[英]destructuring error despite correct destructuring (eslint)

我有一堂課:

export default class DepartmentItem extends React.Component {
  render() {
    const {
      name,
      location,
      position,
      salary,
      age,
      citizenship,
      description
    } = this.props.department;
    const { link, tag } = this.props.department.url;
    const { isToggleOn } = this.state;
  }
}

為簡便起見,未添加構造函數。

盡管破壞了道具,但我仍然收到eslint錯誤,說Muse use destructuring props assignment 我相信我已正確執行此操作,並針對AirBnB eslint配置進行了仔細檢查,但錯誤仍然存​​在。

我如何擺脫錯誤(修復錯誤,而不是制定規則忽略該錯誤)。

無需從this.props.department進行選擇,只需嵌套解構即可。

const {
  department: {
    name,
    location,
    position,
    salary,
    age,
    citizenship,
    description,
    url: {
      link, tag
    }
  } = this.props;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM