代码之家  ›  专栏  ›  技术社区  ›  Relm

React Eslint,如果组件props Type需要一个prop,但组件没有使用它,则发出警告

  •  0
  • Relm  · 技术社区  · 3 周前

    考虑下面的组件,当组件不使用时,如何让Eslint发出警告 users 什么时候需要?

    type ItemCardProps={ users:Array; editEnabled:boolean; };

    export const ItemFields=(props:ItemCardProps)=>{ const{editEnabled}=道具; }

    1 回复  |  直到 3 周前
        1
  •  1
  •   W-B    3 周前

    看起来你想启用 react/no-unused-prop-types

    在eslintConfig中

      "rules": {
        "react/no-unused-prop-types": "warn"
      }
    

    注意:您需要安装 eslint-plugin-react

    npm install eslint eslint-plugin-react --save-dev
    

    有关此规则的用例的详细信息: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unused-prop-types.md