Search code examples
reactjseslintreact-props

React Eslint, warn if a component props Type requires a prop, but the component doesn't use it


Consider the component below, how do I get ESlint to warn when a component doesn't use users when it requires it?

type ItemCardProps = {
  users: Array<AccountUser>;
  editEnabled: boolean;
};

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

Solution

  • looks like you want to enable react/no-unused-prop-types

    in your eslintConfig

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

    note: you will need to install eslint-plugin-react

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

    more on use cases for this rule: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unused-prop-types.md