user16645195
user16645195

Reputation:

REACT JS code, after SAVE (CTRL+S) change all the right syntax to a totally wrong syntax. VSCODE

BEFORE SAVE

before ctrl s in react

AFTER

AFTER CTRL S IN REACT

this thing has never happened to me with languages like c++, etc...

in other cases it happens but for the better, for example my html code becomes more orderly and clean.

the interesting fact that the code works. despite more than 20 errors.

Upvotes: 0

Views: 1821

Answers (3)

change the format of the file from babel javascript to javascript react in bottom right in vs code.

Upvotes: 0

CertainPerformance
CertainPerformance

Reputation: 370729

The problem is here:

enter image description here

See how the filename is App.js? That means that it will be automatically formatted for plain JavaScript.

But what you have is not plain JavaScript - you're using JSX syntax, so you need to change the file extension. Name the file app.jsx, and make sure to change modules that import it as well if needed.

Files that contain JSX syntax should have the file extension .jsx.

Only files that have no JSX syntax in them can be named .js.

Another option is to change the formatter for the file to React rather than just plain JavaScript, in the bottom right, eg

enter image description here

but fixing the file extension is a better solution.

Upvotes: 0

Ryan Le
Ryan Le

Reputation: 8412

You probably apply the wrong format to your code

You will need to change your formater or turn auto format onsave off:

Add the following to your settings.json file:

"editor.formatOnSave": true

Upvotes: 1

Related Questions