19

I have been trying to find a proper way to highlight React Code in '.js' files so that it is easier to read in Visual Studio Code. The photo below shows a sample file of how a lot of it is in one color, making it hard to read.

I tried using "jsx" extension by TwentyChung and "react-beautify", but neither of them worked. Can someone please assist? :-)

enter image description here

2
  • 2
    Can you set language mode to JavaScript React in the bottom bar (click where it says 'JavaScript')? I have no trouble with VSCode highlighting React, and I havn't really done anything to configure it. It pretty much worked out of the box for me. Only thing I did was add the following to user configuration: "javascript.validate.enable": false, since the editor chokes on some es6 constructs (spread operator, arrow functions, etc.) with it set to true. Commented Jan 1, 2017 at 22:31
  • thanks! I provided more details on what the problem was in the answer Commented Jan 2, 2017 at 21:03

10 Answers 10

30

Change the VS CODE color theme to Dark+ and change the language in bottom status bar to java script react. This worked for me

Sign up to request clarification or add additional context in comments.

3 Comments

I believe changing the language in the bottom status bar to JavaScript React is the only action that's needed!
(related to phsource comment above): I had to also switch to another theme - was using "Tomorrow Night" and all JSX was red even with the Javascript React language mode set.
The Dark+ change worked perfectly. Thanks
18

JSX highlighting works out of the box in VS code and JSX files are already associated with JavaScript React language mode. If you want to enable JSX syntax coloring in .js files click on the language name in the status bar and select JavaScript React language mode. You can also associate .js files with JavaScript React if you don't want to do this every time. Make sure you have the latest version of VS Code.

4 Comments

turns out the problem was that I somehow enabled "Javascript Atom Gramar" package and it made all the code un-hlighted. After disabling it, everything worked fine per your instructions!
Also, you need to be using a theme that is compatible with React's syntax. I saw render's returns as all one color until I switched to Community Material Theme.
It also worked for me after I changed my VS Code Workbench Color Theme to Dark+. Would be good if there's a list of theme that supports JavaScript React language mode.
What if you don't have that language available in VS Code, what installs it?
15

Disabling this extension fixed it for me. It specifically happened this day November 17,2022 3 of my workmates were having the same problem.

Disable this

3 Comments

Also installing previous version works too.
There's a new update now, updating it fixed the bug for me.
Interestingly this worked!
5

Just uninstall this plugin and install it again in the vs code extensions:

Name: JavaScript and TypeScript Nightly

VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-vscode.vscode-typescript-next

Comments

3

I just added this to settings.json and it worked for me, so you can give it a try.

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

Comments

2

For Me Here is what worked

  1. Update the vscode by downloading the latest verrsion

https://code.visualstudio.com/download

2.Open Vscode click extension and search this extension

Javascript Atom Gramar

Just disable the extension.

3.Close and open vscode, now u should see colors in your jsx code.

Hope this will help some one in future

Comments

1

disable the extension named Javascript Atom Grammar works for me

2 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
Please at least describe the steps you have taken.
1
  1. Select Language mode as "Javascript React".
  2. Go to Settings -> Color theme -> Select "Dark+" theme.

Comments

1

Click: Ctrl + K + T

Change the color theme settings to dark+(default) , it worked for me.

And select the appropriate language from bottom status bar: enter image description here

Comments

-1

VS Code highlights code via extensions, not with ESLint or Prettier, which are sometimes assumed to do the job. Out of the box, VS Code supports React and JSX natively. You can also adjust VS Code's settings.json file. Here's an example off how that might look:

{
    "window.zoomLevel": 0,

    // Solarized-dark theme
    "workbench.colorTheme": "Solarized-dark",

    // Changes the highlight color in solarized-dark, which I can't see
    "workbench.colorCustomizations": {
      "editor.selectionBackground": "#5b455e",
      "editorBracketMatch.border": "#555",
      "editorBracketMatch.background": "#5b455e"
    },

    // Number of spaces in a tab
    "editor.tabSize": 2,

    // Insert spaces when pressing Tab. This setting is overriden
    // based on the file contents when `editor.detectIndentation` is true.
    "editor.insertSpaces": true,

    // Override whatever the files say and give me 2 spaces per tab
    "editor.detectIndentation": false,
    "workbench.startupEditor": "newUntitledFile",
    "explorer.confirmDelete": false,
    "explorer.confirmDragAndDrop": false,
    "javascript.updateImportsOnFileMove.enabled": "always"
  }

VS Code modifies syntax highlighting automatically, but it's not perfect. You can also adjust the detection by clicking on the auto-detected language on the right side of the bottom toolbar:

VSCode language detection

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.