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

Extension removes global React from imports #19

Open
muerwre opened this issue Aug 17, 2022 · 6 comments
Open

Extension removes global React from imports #19

muerwre opened this issue Aug 17, 2022 · 6 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@muerwre
Copy link

muerwre commented Aug 17, 2022

In order to write React components you need to import React from react.

This extension removes it, when optimizing imports.

@kcmr
Copy link
Owner

kcmr commented Aug 17, 2022

I need to detect if you are using the new JSX transform that doesn't require importing React or not. The native "Organize Imports" from VS Code detects this when you are in a project, so I suppose it is possible. Another option would be to add a new setting to exclude some imports that could be set per project. Let me think about this.

In the meantime you can use React in your code (React.useState, etc.) as a temporary workaround to prevent this behavior.

@kcmr kcmr self-assigned this Aug 17, 2022
@Sanford284
Copy link

Sanford284 commented Aug 24, 2022

I have the same question. Maybe add a new setting to exclude some words is a better way :)

the temporary way I used is creating a global snipptes.

@kcmr
Copy link
Owner

kcmr commented Aug 24, 2022

I started working on this but I haven't had time to finish. My idea for this is to work the same than native VS Code Organize Imports, that is React import is removed or not depending on the jsx field in jsconfig.json or tsconfig.json of the project. See this issue.

So, if you have react as the value for jsx in compilerOptions, the import won't be removed:

{
  "compilerOptions": {
    "jsx": "react"
  }
}

For me, this is the most convenient because the desired behavior depends on the project settings (if you are using or not the new JSX transform). If the behavior depends on an extension setting, then you'll probably need to add a workspace settings per project (.vscode/settings.json). The other way is transparent for the user and takes advantage of the existing compilation settings for other tools (tsc).

@kcmr kcmr added the bug Something isn't working label Jan 10, 2023
@savissimo
Copy link

Hello! Any news on this?

@kcmr
Copy link
Owner

kcmr commented Jun 14, 2023

@savissimo sorry, not yet. I'll have some free time in August to continue working on this.
I'm also open to accept collaborations to fix this issue.

@kcmr kcmr added the help wanted Extra attention is needed label Jun 14, 2023
@timwhite06
Copy link

Would it be possible to have a .config.json to include imports that you do not want automatically deleting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants