How to make VS Code change language to JavaScript React when open a JSX file

Viewed 24254

Currently, when I open a .jsx file the default language is plain JavaScript. Is there a way to set the editor to change the language based on the file extension?

Ideally, I can put this setting in both my local setting config file OR the workspace specific config file.

The version I am using is Version 1.15.0-insider (1.15.0-insider).

7 Answers

Press cntrl + , and add this to user settings JSON file:

"files.associations": {
    "*.js": "javascriptreact"
}

like this: enter image description here

why not like this ?

Open your setting.json in vscode and add or edit files.associations like below:

"files.associations": {
    "**/src/**/*.js": "javascriptreact",
    "**/src/**/*.jsx": "javascriptreact"
}

I wounder to know why no one shared this on internet (at least I haven't found).

This code will auto detect your react files since we wrote path for it, it will find src folder of your react app and detect all of the .js, .jsx files as react and you can still have your .js files out of src folder like public or anywhere else you like.

I have to let you know, in your non react project all of .js, .jsx files inside of src folder gonna detect as react file as well because we wrote the setting like this and I don't know any better way.

press ctrl+shift+P and then go to user settings, after that, Search for file.associations and then click add item. In the key input-field enter *.js and in the value input-field enter javascriptreact

Open that JavaScript file. On the bottom left You can see the language"JavaScript". Click on it and select "JavaScript React".

Now Done:)

Related