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
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.
You can use hot key Ctrl+M (Command+M) to beautify your JSX file.
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.
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.
In addition to the above. If you click 'Configure File Association for .js' you can set all .js files to Javascript React
change vscode preferences settings > user settings below:
"files.associations": { "*.js":"javascriptreact" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With