Skip to content

Yet another false no-unused-props trigger #974

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

Closed
miraage opened this issue Nov 23, 2016 · 1 comment
Closed

Yet another false no-unused-props trigger #974

miraage opened this issue Nov 23, 2016 · 1 comment

Comments

@miraage
Copy link

miraage commented Nov 23, 2016

class Example extends Component {
  static propTypes = {
    classNames: PropTypes.array,
    min: PropTypes.number,
    max: PropTypes.number,
  };

  // rest is omitted..

  render() {
    const { classNames } = this.props;
    const sliderProps = _.pick(this.props, ['min', 'max']);

    // rest is omitted..
  }
}

In this way min and max are marked as unused.

@ljharb
Copy link
Member

ljharb commented Nov 23, 2016

The native way to write this is:

const { classNames, min, max } = this.props;
const sliderProps = { min, max };

It's not scalable or practical for eslint-plugin-react to know what _.pick (or any other arbitrary function) does, and since it can be done easily in native syntax, that's what I'd recommend.

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

3 participants