2

When I press ctrl + K + D to format my javascript file which contains react code, the formatting gets destroyed.

Typescript complains about the formatting, nevertheless the code runs fine.

JSX element has no correspondig closing tag

Is there an extension available which formats the react file with .js extension correctly?

enter image description here

1
  • 1
    Prettier might be a nice alternative.
    – Tholle
    Jun 27, 2018 at 20:43

1 Answer 1

5

There is Prettier but to make it work properly you need to use .jsx extension for files with jsx.

Sometimes it conflicts with beautify so to make it work without adding .jsx you may need to add this to your vs-code config.

"beautify.ignore": [
   "**/*.js",
   "**/*.jsx"
]
3
  • 1
    my first steps with reactjs :D
    – Legends
    Jun 27, 2018 at 20:50
  • I read that the use of .jsx is not recommended (thread). Is there a way to format it adequately without using jsx extension?
    – Legends
    Jul 5, 2018 at 15:07
  • 1
    I found out that it may not work properly because of conflicts with beautify github.com/prettier/prettier-vscode/issues/454 But updating your config should help with it. Jul 5, 2018 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.