8

I have just started learning React Native. I am using Visual Studio Code for editing. Whenever I save my file it is inserting spaces in my JSX code. This reduces the readability of the code. This is code before I save the file

Before Saving the File:
Before Saving the File

This is File after saving:
This is File after saving

I have tried editing VS Code settings

"javascript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false,
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false

But it did not help.

Is there any solution to this problem?

Gama11
  • 31,714
  • 9
  • 78
  • 100
sandeep
  • 190
  • 1
  • 2
  • 12
  • Please find a detail step-by-step solution for this https://stackoverflow.com/questions/44993808/visual-studio-code-changes-format-react-jsx/67938283#67938283 – CostaIvo Jul 02 '21 at 15:46

3 Answers3

14

I managed to resolve this by manually changing the language of the file to javascriptreact instead of javascript.

Screenshot:
enter image description here

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
1

Or you could also rename the file changing its extension from .js to .jsx and VSCode will understand that the file is React.

Edu Garcia
  • 21
  • 3
1

I had this problem and I solved by making js-css-html formatter extension disable and closing the vs code and restart