Reputation: 1239
Visual Studio Code now supports JSX on 0.8 version, but looks like the only way to activate it is with a .jsx
file extension. It is not on the list to change the language mode manually, the nearest option is JavaScriptReact
, but it doesn't parse the JSX tags.
I'm in a project with a lot of .js
files with JSX and I can't change it.
Is there any other way to use JSX syntax without the .jsx
extension?
Upvotes: 63
Views: 56245
Reputation: 314
Click on the bottom right on VS Code Editor where it says Javascript. You will see an option to Select the language Mode, here you can search for JavaScriptReact and select. That's it.
Upvotes: 1
Reputation: 1
1-Press F1 (in Visual Studio Code)
2-Type "extension" in the appearing text field
3-Pick "Extensions: Install Extension"
3-Type "ext install jsx"
4- install JS JSX Snippets
5-Restart Visual Studio Code
Upvotes: 0
Reputation: 1559
I would feel the below is the easiest way of formatting the code
Click on the bottom right on VS Code Editor where it says Javascript.
You will see an option to Select the language Mode, here you can search for JavaScriptReact and select. That's it. This should solve your problem.
Upvotes: 11
Reputation: 1834
Although Dionys' answer works there is a better way to do this in more recent versions of Visual Studio Code.
Go to File>Prefrences>Settings
and then scroll down and find "Emmet" open the tab and you should see the following text
// Enable Emmet abbreviations in languages that are not supported by default. Add a
mapping here between the language and emmet supported language.
// E.g.: {"vue-html": "html", "javascript": "javascriptreact"}
"emmet.includeLanguages": {},
So just follow the instructions and add "emmet.includeLanguages": { "javascript": "javascriptreact" }
on the json at the right panel ( which will overwrite the user settings ).
Upvotes: 6
Reputation: 3113
Change your user settings or workspace settings as below:
// Place your settings in this file to overwrite the default settings
{
"files.associations": {
"*.js": "javascriptreact"
}
}
Note: You might need to restart VSCode.
Upvotes: 158
Reputation: 252
Took me a while to figure this out but – JSX is already part of Emmet – which is part of VS Code. I've told Emmet to also (additionally) make JSX snippets available in regular JS files.
Just put this in your settings file:
"emmet.syntaxProfiles": {
"javascript": "jsx"
}
Upvotes: 6
Reputation: 30165
There is now a VS Code extension that allows .js
files to be treated as .jsx
files.
Unfortunately the readme for the extension also warns:
when you install this extension you will loose all the existing language support provided for .js files
Fortunately VS Code is now very close to adopting Salsa, which means soon the js-is-jsx issue should be completely resolved.
Upvotes: 3
Reputation: 4892
Just install an extension:
Source:
https://code.visualstudio.com/docs/editor/extension-gallery?pub=TwentyChung&ext=jsx https://marketplace.visualstudio.com/items/TwentyChung.jsx
Upvotes: -2
Reputation: 346
I could do it, but "not React JS files" are also show with JavaScriptReact mode.
Upvotes: 7