简体   繁体   中英

How to format React Codes in Visual Studio Code?

When auto-formatting React codes in VSCode it makes errors. I am using the Prettier extension. So what is the best code formatted for this?

Prettier is extracly of you need. If you want to personalized format code jsx, you can configuration prettier with your style.

Use vscode internal react formatter, it's very good:

在此处输入图像描述

you can find both React & TypeScript React code formatter:

在此处输入图像描述

Finally, I have found a way to do it. In the vscode settings, I have to change to default format to prettier.

在此处输入图像描述

As well as on the project it is needed to create a.prettierrc file with suitable configurations for the project.

在此处输入图像描述 在此处输入图像描述

{
  "trailingComma": "es5",
  "tabWidth": 2,
  "semi": true,
  "singleQuote": true
}

And if you do not need it, you can always enable to format the code without the.prettierrc file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM