Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual studio code changes format (React-JSX)

I've the following snippet in my index.js

class App extends Component {     render() {         return ( <div style = { styles.app } >             Welcome to React!             </div>         )     } } 


The code works, but every time I save (ctrl+s) visual studio format the jsx like that:

class App extends Component {     render() {         return ( < div style = { styles.app } >             Welcome to React!             <             /div>         )     } } 

How can I solve this? thanks

like image 859
omer727 Avatar asked Jul 09 '17 06:07

omer727


People also ask

How do I fix the format in VS code?

The code formatting is available in Visual Studio Code through the following shortcuts: On Windows Shift + Alt + F. On Mac Shift + Option + F. On Linux Ctrl + Shift + I.

How do I beautify a JSX file?

You can use hot key Ctrl+M (Command+M) to beautify your JSX file.

In which format JSX is converted into in Reactjs?

What's a JSX Transform? Browsers don't understand JSX out of the box, so most React users rely on a compiler like Babel or TypeScript to transform JSX code into regular JavaScript. Many preconfigured toolkits like Create React App or Next.


2 Answers

In the end what did the trick was changing the file format from JavaScript to JavaScript React on the bottom toolbar. I'm publishing it here for future reference since I didn't find any documentation on this topic.

enter image description here

In addition to the above. If you click 'Configure File Association for .js' you can set all .js files to Javascript React

like image 130
omer727 Avatar answered Oct 04 '22 08:10

omer727


change vscode preferences settings > user settings below:

"files.associations": {         "*.js":"javascriptreact"     } 
like image 38
dotdot Avatar answered Oct 04 '22 08:10

dotdot