Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react/prop-types emits warning for inline components #2809

Closed
adnasa opened this issue Sep 29, 2020 · 1 comment
Closed

react/prop-types emits warning for inline components #2809

adnasa opened this issue Sep 29, 2020 · 1 comment

Comments

@adnasa
Copy link
Contributor

adnasa commented Sep 29, 2020

Hey.
I attempted to upgrade eslint-plugin-react in my repo from v7.20.6 to v7.21.2,
and react/prop-types rule emits warnings.

Actual source code (simplest case)

const SelectField = (props) => (
  <div className={styles['select-wrapper']}>
    <SelectInput
      id={props.id}
      name={props.name}
      value={props.quantity}
      options={quantityOptions}
      onChange={handleSelectChange}
      components={{
        // eslint-disable-next-line react/display-name
        Option: (optionProps) => (
          <React.Fragment>
            {optionProps.value === `${props.maxSelectableValue}` && (
              <span className={styles.separator} />
            )}
            <SelectInput.Option {...optionProps} />
          </React.Fragment>
        ),
      }}
      menuPortalTarget={document.body}
      menuPortalZIndex={props.menuPortalZIndex}
      data-testid="quantity-selector-select-input"
    />
  </div>
)
SelectField.displayName = 'SelectField'
SelectField.propTypes = {
  id: PropTypes.string,
  name: PropTypes.string,
  onChange: PropTypes.func.isRequired,
  quantity: PropTypes.string,
  menuPortalZIndex: PropTypes.number,
  maxSelectableValue: PropTypes.number.isRequired,
}

In the example above, optionProps.value === props.maxSelectableValue emits a react/prop-types warning,
although a prop-type validation was defined for maxSelectableValue.

I'm not sure if I should file this as a bug. I was looking through the changelogs and previous PR and discussions up to v7.21.2 and couldn't find hints as to how I can migrate this. I welcome suggestions, clarity if this is be design and what I can do next.

What I expected

react/prop-types to not emit warning for props.maxSelectableValue for the case above.

context information:

SelectInput is a component of an external library that I import. It wraps react-select

configuration

base configuration
module.exports = {
  extends: [
    '@commercetools-frontend/eslint-config-mc-app',
    'plugin:testing-library/react',
  ],
  plugins: ['graphql', 'react-hooks'],
  rules: {
    'max-classes-per-file': 0,
    'react-hooks/rules-of-hooks': 'error',
    'react-hooks/exhaustive-deps': 'warn',
    'jest/expect-expect': 'off',
    'testing-library/prefer-presence-queries': 'error',
    'testing-library/await-async-query': 'error',
    'jest-dom/prefer-enabled-disabled': 'warn',
  },
  settings: {
    react: {
      version: 'detect',
    },
  },
}

Note that the config for @commercetools-frontend/eslint-config-nc-app can be found here


off topic:
Regarding react/display-name, I stumbled on cases where disabling it still emits warnings (not in this scenario)
I'll create a different issue for that, if I can't resolve it

@ljharb
Copy link
Member

ljharb commented Oct 5, 2020

Fixed in #2807, per #2807 (comment).

@ljharb ljharb closed this as completed Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants