Visual Studio Code Change Format (React-JSX)

I have 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) a visual studio format, jsx likes it:

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

}

How can i solve this? thank

+33
source share
9 answers

In the end, what happened by changing the file format from JavaScript to JavaScript React in the bottom toolbar. I am posting it here for future reference, as I have not found any documentation on this topic.

enter image description here

In addition to the above. If you click Configure File Associations for .js, you can install all .js files in Javascript React.

+123

vscode> :

"files.associations": {
        "*.js":"javascriptreact"
    }
+22

, .jsx vscode.

, vscode.

, , .js

+10

Prettier ( ) :

"prettier.jsxBracketSameLine": true

linebreak JSX.

(Alt+Shift+F) , .

+3

, javascript . ( ).

- , , / JS.

JT-CSS-HTML Formatter. JS-CSS-HTML Formatter .

+2

, response-beautify, jsx-.

prettydiff/esformatter javascript, JSX, typescript, TSX.

+1

, , "". , .

+1

, . settings.json

{
    "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
    "workbench.startupEditor": "welcomePage",
    "window.zoomLevel": 1,
    "emmet.includeLanguages": {
        "javascript": "javascriptreact",
        "vue-html": "html"
    },
    "editor.formatOnSave": true,
    "javascript.updateImportsOnFileMove.enabled": "always",
    "editor.wordWrap": "on",
    "editor.tabSize": 2,
    "editor.minimap.enabled": false,
    "workbench.iconTheme": "vscode-icons",
    "eslint.autoFixOnSave": true,
    "eslint.alwaysShowStatus": true,
    "beautify.ignore": [
        "**/*.js",
        "**/*.jsx"
    ],
    "prettier.jsxSingleQuote": true,
    "prettier.singleQuote": true
}

"beautify.ignore": ["**/*.js","**/*.jsx"]
+1

VSC JSX, settings.json.

Code > Preferences > Settings

, edit settings.json :

"files.associations": {
    "*.js": "javascriptreact"
}
0

Source: https://habr.com/ru/post/1681053/


All Articles