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

jsx-fragments: allow Fragment syntax option #3813

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nicmosc
Copy link

@nicmosc nicmosc commented Sep 2, 2024

Description

Right now one can specify either syntax or element, however element automatically falls back to using React.Fragment which is not supported in the case the variable is not exposed as an UMD global - the case when using es modules.

This option allows to use modules instead and import the Fragment component from the react library

Note: we need this behaviour for our team so we've patched the library with the same changes you see here for now.

Usage

'react/jsx-fragments': ['warn', 'elementShort'],

Showcase

Screen.Recording.2024-09-02.at.13.27.46.mov

Open to:

  • using a different option name instead of elementShort e.g. module?
  • if there is a way to achieve this without modifying the rule OR there is a way to infer this from the project settings it's probably better - any ideas?

Right now one can specify either `syntax` or `element`, however `element` automatically falls back to using `React.Fragment` which is not supported in the case the variable is not exposed as an UMD global - the case when using es modules.

This option allows to use modules instead and import the `Fragment` component from the react library
@ljharb
Copy link
Member

ljharb commented Sep 2, 2024

Historically, you’re required to have React in scope for jsx to work, so this never came up until the new jsx renderer in React 17.

However, in a modern codebase, why wouldn’t you always prefer the syntax?

@ljharb ljharb marked this pull request as draft September 12, 2024 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants