Open muerwre opened 2 years ago
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.
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.
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
).
Hello! Any news on this?
@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.
Would it be possible to have a
In order to write React components you need to import React from react.
This extension removes it, when optimizing imports.