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

Allowing use of the index in combination with other data react/no-array-index-key #2356

Closed
tomprats opened this issue Jul 23, 2019 · 1 comment

Comments

@tomprats
Copy link

This is similar to why #1124 was added but I was wondering if it'd be possible to update this rule instead of just to disable it. Here's an example:

names = ["Tom", "Joe", "Tim", "Tom"];
names.map((name, index) => (<li key={`${name}-${index}`}>{name}</li>));

In a list like this, sometimes the data isn't unique by itself, but it is when combined with it's position.

Would it be possible to update the rule to allow cases like this?

@ljharb
Copy link
Member

ljharb commented Jul 23, 2019

If you're using the index, then using other data adds zero value - just use the index. If you can only use the other data, then don't use the index.

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