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

Enable allowExpressions for the react/jsx-no-useless-fragment rule #24

Closed
codybrouwers opened this issue Jul 8, 2022 · 2 comments
Closed

Comments

@codybrouwers
Copy link
Member

The react/jsx-no-useless-fragment has a allowExpressions configuration option that allows fragments that have a single expression in them like:

const arrayOfElements = array.map((item) => {
  return <span key={item}>{item}</span>
})
<>
  {arrayOfElements}
</>

This is useful for TypeScript when in an component you want to return a single array of elements but if you return just the arrayOfElements then the return type of the component becomes JSX.Element[] which when you use the component produces an error:

'Component' cannot be used as a JSX component.
  Its return type 'Element[]' is not a valid JSX element.
    Type 'Element[]' is missing the following properties from type 'ReactElement<any, any>': type, props, keyts(2786)

So wrapping the array with the fragment fixes the type error but causes the ESLint error, so enabling the allowExpressions option allows for this specific use case.

@vercel-release-bot
Copy link
Collaborator

🎉 This issue has been resolved in version 4.0.0-canary.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@vercel-release-bot
Copy link
Collaborator

🎉 This issue has been resolved in version 4.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

No branches or pull requests

3 participants