Change language to JSX in Visual Studio Code
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?
Solution 1:
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.
Solution 2:
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.
1.
Solution 3:
I could do it, but "not React JS files" are also show with JavaScriptReact mode.
- open file C:\Program Files (x86)\Microsoft VS Code\resources\app\plugins\vs.language.javascript\syntaxes\javascriptreact.json (probably, need to open with administrator privileges.)
- change "jsx" to "js" in array "fileTypes".
- restart app, close opened js files, and reopen.