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

eslint-plugin-react(jsx-key) - false positive with missing key inside React.Children.toArray() #4421

Closed
kristho91 opened this issue Jul 23, 2024 · 5 comments · Fixed by #4945
Assignees
Labels
A-linter Area - Linter C-bug Category - Bug good first issue Experience Level - Good for newcomers

Comments

@kristho91
Copy link

This triggers an error with oxlint:

{React.Children.toArray(items.map((item) => {
  return (
    <div>
      {item}
    </div>
  );
}))}

But it does not with eslint. When using .map inside React.Children.toArray() a key should not be necessary (to my understanding)

@kristho91 kristho91 added the C-bug Category - Bug label Jul 23, 2024
@DonIsaac DonIsaac added the A-linter Area - Linter label Jul 23, 2024
@Dunqing Dunqing added the good first issue Experience Level - Good for newcomers label Jul 24, 2024
@vHugoObject
Copy link
Contributor

Can I take this?

@Dunqing
Copy link
Member

Dunqing commented Jul 30, 2024

Can I take this?

Sure

@AlfredoPrograma
Copy link

AlfredoPrograma commented Aug 13, 2024

Hello folks! Is right to pass a non children array of elements to the React.Children.toArray function?

The docs explicitly exposes that:

children parameter should be the value of the children prop received by the component.

So I'm not sure if automatic calculation keys can work with non children array of elements. If anyone has some clue about it, let me know and I contribute to this issue!

@kristho91
Copy link
Author

I have just tested this in the new oxlint 0.8.0 . There is still a minor tweak, that needs to be fixed.
It still have a false positive when an empty fragment is used:

{React.Children.toArray(items.map((item) => {
  return (
    <>
      {item}
    </>
  );
}))}

@vHugoObject
Copy link
Contributor

My apologies, I didn't add an if statement to check for React.Children for fragments. Will open up another pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter C-bug Category - Bug good first issue Experience Level - Good for newcomers
Projects
None yet
6 participants