How to auto indent jsx in VSCode
Try changing the language mode to JavaScript React.
- Open the commands palette.
- Type
change language mode
- Press Enter
- Type
javascript react
- Press Enter
Once that's done, you'll see the JavaScript React mode in the bottom left corner.
Once you're in that mode, try again to format the document.
Change the language to Javascript React
(see other answers for instructions) then use the following command:
alt + shift + f
use the extension "Prettier - Code formatter", by Esben Petersen. it will auto format on save, assuming your file is a jsx file.