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

False Missing "key" prop for element in iterator from jsx-key #320

Closed
lencioni opened this issue Nov 18, 2015 · 2 comments · Fixed by #332
Closed

False Missing "key" prop for element in iterator from jsx-key #320

lencioni opened this issue Nov 18, 2015 · 2 comments · Fixed by #332

Comments

@lencioni
Copy link
Collaborator

First of all, great work on the jsx-key rule. I think this will save people a lot of time.

Now, I have the following code:

<TransitionMotion
  styles={this._getStyles()}
  willEnter={this._willEnter}
  willLeave={this._willLeave}
  >
  {styles =>
    <div>
      {Object.keys(styles).map(key =>
        <Toast
          action={styles[key].action}
          key={key}
          message={styles[key].message}
          opacity={styles[key].opacity}
          translateY={`${styles[key].translateY}%`}
        />
      )}
    </div>
  }
</TransitionMotion>

using the jsx-key rule, I am getting the missing key prop on the line that has the opening <div>. I might be misunderstanding when key should be used, but I don't think I need one here. And, if I do, then the error message that this rule outputs is misleading since it claims that I am in an iterator when I am not.

I noticed in the documentation:

Also, if you have some prevalent situation where you use arrow functions to return JSX that will not be held in an iterable, you may want to disable this rule.

which I believe is referring to this situation, but I figured I'd open an issue for this anyway in case there happens to be a solution lurking.

@lencioni
Copy link
Collaborator Author

I am also noticing that this gives false errors on pure functional stateless components that are now available as of React 0.14:

const MyComponent = () =>
  <div>
    ...
  </div>;

@silvenon
Copy link
Contributor

eslint-plugin-react naively checks just if the element is a part of an arrow expression. I'm setting up a PR…

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

Successfully merging a pull request may close this issue.

2 participants