score:150

Accepted answer

Visual studio code detect .jsx extensions and add emmet support by default ( i'm using VS code 1.8.1)

But if you prefer to use .js extention for all your react files - you can associate JavaScript React mode with .js files in bottom right corner of VS Code window.

How to do this step by step (gif)

enter image description here

Update 2021

For those who just want to copy-paste the code:

"emmet.syntaxProfiles": {
  "javascript": "jsx"
}

If the solution above doesn't work, try this:

"emmet.triggerExpansionOnTab": true,
"emmet.includeLanguages": {
  "javascript": "javascriptreact"
}

Tested with VS Code v1.56.2.

score:0

just name the file you are working on from .js to .jsx and you are fine .

score:1

Autocomplete for React Babel was working fine until yesterday for me.

None of these answers helped so I just restarted my computer. Worked like a charm ;)

score:1

I was working on various projects and I have a big settings file.

I checked settings and found out that this settings was ruining that all.

"emmet.showExpandedAbbreviation": "inMarkupAndStylesheetFilesOnly"

So I commented it. And everyhting works perfectly in React Apps. Thanks

score:1

Only work in JSX files. Let it not work with JS.

"files.associations": {
"*.js": "javascript",
"*.jsx": "javascriptreact",
},
"emmet.triggerExpansionOnTab": true,
"emmet.includeLanguages": {
    "javascriptreact": "javascriptreact"
},

score:2

It took me two steps to get auto-closing tags in JSX.

  1. Follow Kehkashan Fazal's instructions above about setting "emmet.includeLanguages"
  2. Download the Auto Close Tag extension from VSCode (formulahendry.auto-close-tag)

And now you have nice auto-closing JSX tags!

score:2

Follow these two steps only:

  1. On bottom of VSCode where detect language click on that

1st step

  1. Click on "Configure 'Javascript(Babel)' language based settings..." or what ever

2st step

  1. paste this code on it separate first by comma ',' and save it.

"emmet.includeLanguages": { "javascript": "javascriptreact" }, "emmet.triggerExpansionOnTab": true

3rd step

score:3

Adding an item called javascript with value javascriptreact in the emmet section in settings worked for me.

a screen shot of my settings

score:3

Changing the extension from ".js" to ".jsx" will do the job. But in a case that you want to keep ".js" extension follow below steps.

Go to

Files > Preferences > Settings

In the settings tab you will see two tabs named 'user' and 'workspace' (look close to the bottom of search bar). Both the tabs will show you same settings but user settings will effect for all the projects in VS Code while workspace will effect only for current project. Choose whatever option you want, workspace or user.

And then on the left side menu bar you have to go

Extensions > JSON

Then at the right side you can see several settings. Scroll down a little bit and you will see something like this.

JSON:Schemas
Associate schemas to JSON files in the current project.
Edit in settings.json

Click on "Edit in settigns.json". It will open a json file. Add below code to the json file.

"emmet.triggerExpansionOnTab": true,
"emmet.includeLanguages": {
    "javascript": "javascriptreact"
}

And save the file. Now go and check if your js file supports for jsx auto-completion. This has been tested with

VS Code versino 1.61.2.

P.S. -: Following part is only for the learners who don't know about json.

Copy and paste the above code to the bottom of settings.json file as shown in the following image. Don't forget to add a comma (pointed by red arrow) and the code should be pasted before the last closing curly bracket (pointed by yellow arrow).

If you choose workspace settings tab then there might be nothing in you settings.json file. If so just paste the code inside the curly brackets. enter image description here

score:4

you can use The Auto Close Extention In Visual Studio Code . ps. when you install the extension, the autocomplete won't work until you reload VS Code , just Reopen VS Code , or go to auto close tag extension and click Reload.

link of the auto close tag Extension

score:5

I went throw all answers and this config worked for me. had to include language as well as add syntaxProfile. without the trigger expansion nothing worked but now I only press Tab button to get the result.

"emmet.includeLanguages": {
    "javascript": "javascriptreact"
},
"emmet.syntaxProfiles": {
    "javascript": "jsx"
},
"emmet.triggerExpansionOnTab": true

score:5

  1. Just go to settings in vscode.
  2. You can see a search bar in setting type emmet.
  3. Scroll down, there is an option include language.
  4. Click on the add item button in include language.
  5. Add item as javascript and value as javascriptreact.

if you get confused, please refer to the picture below: enter image description here

score:6

I solved the problem simply by following the steps below:

  1. On the left bottom of VSCode click to Javascript
  2. Then on the top, you will see a list, click on "Configure 'Javascript' language based settings"
  3. Add these lines to the file:

    "emmet.triggerExpansionOnTab": true,
     "emmet.includeLanguages": {
       "javascript": "javascriptreact"
    }
    

If you want to more details, you can check this link.

score:6

Easy & Modern way to enable the auto suggestions for JSX for ReactJs is Shown in GIF below.

for Windows => File > Preferences > Settings

for MacOs => Code > Preferences > Settings

then follow the steps shown in GIF.

enter image description here

score:8

2019 Update


Auto closing tags in .html, .js, and .jsx

Works out of the box. That is, after typing in the closing bracket to the opening tag, the closing tag will be inserted automatically.

Emmet with basic HTML in .jsx files

Works out of the box.

Emmet with basic HTML in .js files:

Add the following setting, required for Emmet abbreviation suggestions, and required for tab expansion to work consistently.

  "emmet.includeLanguages": {
    "javascript": "javascriptreact"
  },

Emmet with custom tags (e.g. React Components) in both .js and .jsx files

Add the following setting:

  "emmet.triggerExpansionOnTab": true,

Note that with this setting, Emmet will expand all words as custom tags (not just React component names)

Also note that when using Emmet to expand React components as custom tags, you have to actually choose the component name from the suggestion list and complete that first (or type out the whole name manually and close the suggestion menu with the escape key). After the word expands, you then have to tab again to get Emmet to expand the custom tag.

There's an active feature request to potentially remove this extra step (automatically expand when selecting the suggestion so that it works the same way as expanding standard html tags would).


Troubleshooting

Ensure you have the latest version of VSCode.

Ensure you did not change the following default settings:

"html.autoClosingTags": true,
"javascript.autoClosingTags": true,
"typescript.autoClosingTags": true,

// read the GitHub issue listed above if you're curious why this is required).
"editor.wordBasedSuggestions": true,

// you obviously don't want javascript, javascriptreact included in here if you want Emmet to be available in those files
"emmet.excludeLanguages": [
    "markdown"
],

score:10

None of those solutions worked... but the Auto Close Tag extension does! https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-close-tag

score:12

Simple answer in 2020

First, select the File Association in the bottom-center-right of the window. enter image description here

Second, select Configure File Association for .js from the menu that drops down at the top-center of the window. Change it to JavaScript React. enter image description here

score:14

2018

I'm using VSCode (ver 1.27.2)

Base on my experienced, even though I'm working with React . The detected language on my VSCode is still vanilla JavaScript. And emmet did not work.

  • One of the ways to make it work again is change the VSCode detected language to JavaScript React. This is for single JS file only.

vscode options

  • To change it once entirely, you need to associate it.

two

Click Configure File Association for .js...

three

And select JSX , which in my case, I already did.

four

  • For Workplace Setting, and last if none of them work for you. Go to Preference of just to ctrl + , (comma) to open it.

Type and search for emmet or Emmet. Then copy the Setting you want to override. In my case:

{
    "emmet.triggerExpansionOnTab": true,
    "emmet.includeLanguages": {
        "javascript": "javascriptreact"
    },
}

Note: I didn't try to use jsx only javascriptreact.

settings

I implemented the second and third step. And I can now do Emmet.

score:46

Just select the appropriate Language mode at the bottom-right on the screen: set it to JavaScript React.

score:57

If someone is still struggling with this issue:

I have discovered that simply setting

"emmet.syntaxProfiles": {
     "javascript": "jsx" 
 },

does not enable HTML completion. But, using:

"emmet.includeLanguages": {
    "javascript": "html"
}

does.

According to emmet docs:

"emmet.includeLanguages": {}

Enable emmet abbreviations in languages that are not supported by default. Add a mapping here between the language and emmet supported language.
Eg: {"vue-html": "html", "javascript": "javascriptreact"}

score:228

2019: Straight-to-the-point answer for React

The most straight-forward way to get JSX/HTML autocomplete in your React projects is to add this to your user settings or workspace settings (<project-path>/.vscode/settings.json):

      "emmet.includeLanguages": {
        "javascript": "javascriptreact"
      },
      "emmet.triggerExpansionOnTab": true

You may have to restart VS Code for the change to take effect.

P.S. If you're not doing this mapping for a React.js project, then KehkashanFazal's answer should probably work for you.


Related Query

More Query from same tag