Follow these steps:
CTRL + SHIFT + P- Format Document (in pop-up bar)
- Select
Format Document - Select
Configure Default Formatter... - Select
Prettier - Code formatter
To enable Format On Save
CTRL + SHIFT + P- Preferences Open Settings (UI) (in pop-up bar)
- Type
Format On Save - Enable
Format On Saveif it is not checked
Done!
Answer from Yakupguly Malikov on Stack OverflowVideos
What is a code formatter?
Will this tool fix my broken React code?
What is JSX and why does it need formatting?
Follow these steps:
CTRL + SHIFT + P- Format Document (in pop-up bar)
- Select
Format Document - Select
Configure Default Formatter... - Select
Prettier - Code formatter
To enable Format On Save
CTRL + SHIFT + P- Preferences Open Settings (UI) (in pop-up bar)
- Type
Format On Save - Enable
Format On Saveif it is not checked
Done!
I have had the same issue, even thus I have installed the Prettier extension. It shows later that I have had another extension called JS-CSS-HTML Formatter. I uninstalled JS-CSS-HTML Formatter and kept Prettier, and all problem was solved.
This issue is mentioned here as well.
Hi there,
Is there a preferred formatter for React that you use? I have Prettier but it does not work as well-perhaps a settings issue? Thx
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"
}
» npm install react-formatter