3

I am switching to React from SwiftUI, where I am expecting auto import of components which should be default in VSCode, According to my research. Unfortunately when I type the components, VSCode is not suggesting me the components. I have to manually type the component name also manually import the components, which is very slow and require too much effort.

How can I get auto completion of components and auto import in VSCode 1.57.0?

Tanvirgeek
  • 540
  • 1
  • 9
  • 17

2 Answers2

8

I had exactly the same issue with version 1.57.

Adding "security.workspace.trust.enabled": false to settings.json resolved the issue for me.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Ryuichi
  • 81
  • 1
  • 3
  • Where is settings.json can you please tell me? – Tanvirgeek Jun 14 '21 at 12:51
  • 1
    @Tanvirgeek `shift` + `cmd` + `p` and search for `Preferences : Open Settings (JSON)` and another option is: you can add `.vscode` folder in the project root and add `settings.json` within the folder by yourself but it is effective only for the project. – Ryuichi Jun 14 '21 at 12:54
  • Hey, I have done that. But still no luck. – Tanvirgeek Jun 14 '21 at 13:30
  • Maybe, you export components with `export default`, which does not tell the editor the name of the component. Export component with named export like `export const SomeComponent = () => {}` lets the editor know the name of the component and you can use auto import. If you want to stick to export default, you might have to install some extension, or you can add `index.js` within the folder of the component and export the component like `export { default as SomeComponent } from "./SomeComponent";` – Ryuichi Jun 14 '21 at 14:09
  • @Ryuichi is correct. I changed the way I create my components and now VSCode automatically imports them. The only problem I got now that ESLint does not like it. – captaincustard Aug 04 '21 at 21:39
  • Thanks, solved my import component issue. – Jackson Apr 17 '22 at 13:08
0

You can use a vscode extension.
I recommend to use Reactjs code snippets extension.

Cardoso
  • 962
  • 1
  • 12
  • 30