Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSX or HTML autocompletion in Visual Studio Code

Is there any way to use components or HTML completion in Visual Studio Code? Because typing each letter manually is not good idea when we have classes like Bootstrap etc. For example completion as in Emmet: ul>li*2>a

var React = require('react');  var Header = React.createClass({     render: function () {         return (              <nav className="navbar navbar-defaullt">                 <div className="container-fluid">                     <a href="/" className="navbar-brand">                         <img width="50" height="50" src="images/logo.png" alt="logo" />                     </a>                     <ul className="nav navbar-nav">                         <li><a href="/">Home</a></li>                         <li><a href="/#about">About</a></li>                     </ul>                 </div>             </nav>                  );                 }                 }); module.exports  = Header; 
like image 368
bawa g Avatar asked Sep 04 '16 18:09

bawa g


People also ask

How do I get JSX IntelliSense in VS Code?

Just go to settings in vscode. You can see a search bar in setting type emmet. Scroll down, there is an option include language. Click on the add item button in include language.

How do I enable HTML suggestions in Visual Studio code?

You can trigger suggestions at any time by pressing Ctrl+Space. You can also control which built-in code completion providers are active. Override these in your user or workspace settings if you prefer not to see the corresponding suggestions.

Should you use JSX extension?

It is called JSX, and it is a syntax extension to JavaScript. We recommend using it with React to describe what the UI should look like. JSX may remind you of a template language, but it comes with the full power of JavaScript. JSX produces React “elements”.

How do I use emmet JSX?

Go to settings > extensions > emmet > include languages and add javascript as the item and javascriptreact as the value.


2 Answers

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.

like image 159
Julian Soro Avatar answered Sep 20 '22 08:09

Julian Soro


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.

like image 24
Andrii.Vandakurov Avatar answered Sep 21 '22 08:09

Andrii.Vandakurov