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 false positive when using props to access array element #1259

Closed
Justkant opened this issue Jun 14, 2017 · 4 comments
Closed

Comments

@Justkant
Copy link

Hi everything is here:
capture d ecran 2017-06-14 a 12 26 59

@ljharb
Copy link
Member

ljharb commented Jun 14, 2017

I don't see the propTypes for Setup?

also, please provide code in text form, instead of screenshots :-)

@Justkant
Copy link
Author

Justkant commented Jun 14, 2017

Hi,

  1. I understand that you prefere text instead of screenshots. It was just for saving time at work.

  2. You have no need to see the propTypes for Setup because this is not the problem.

  3. As you can see in the screenshot Left & Right are both destructured from steps not from props.

Code:

const steps = [
  {
    Left: Component1,
    Right: Component2,
  },
];

const Setup = props => {
  const { Left, Right } = steps[props.current];
  return (
    <div className={style.container}>
      <Left {...props} />
      <Right {...props} />
    </div>
  );
};

Setup.propTypes = {
  current: PropTypes.number.isRequired,
};

@Justkant
Copy link
Author

Tomorrow, I'll try this:

const Setup = props => {
  const current = props.current;
  const { Left, Right } = steps[current];
  return (
    <div className={style.container}>
      <Left {...props} />
      <Right {...props} />
    </div>
  );
};

To confirm that the problem occurs when using some props as an index key and destructuring.

@ljharb
Copy link
Member

ljharb commented Jun 15, 2017

I definitely think that const { current } = props; will fix it, but thanks, I think this makes the bug clear :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants