Auto Import of React Components in Visual Studio Code [closed]

Update 2018

VS Code now handles this natively via a jsconfig.json and the JavaScript Language Service.

Create the file jsconfig.json at your project root and make sure to set checkJs to true:

Creating a JS Config file, allows Visual Studio to treat the folder as an Explicit Project. Without it, JS files opened in VS Code are treated as independent units, and there is no common project context between any two files.

Example:

{
  "compilerOptions": {
    "baseUrl": "./src",
    "checkJs": true,
    "jsx": "react"
  }
}

Code Action / Quick Fix

Missing modules will show up with a Code Action (AKA “Quick Fix”) with an option to import. You can click on the lightbulb 💡 or use Ctrl + .

code action > import

Auto Imports / IntelliSense

Auto Imports will show you available components as you type and import them when selected

intellisense > auto import

Further Reading

  • Visual Studio Code Automatic Imports
  • How to add jsconfig.json to existing vscode project w/o breaking it

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)