[英]How to format React Codes in Visual Studio Code?
When auto-formatting React codes in VSCode it makes errors.在 VSCode 中自动格式化 React 代码时会出错。 I am using the Prettier extension.
我正在使用 Prettier 扩展。 So what is the best code formatted for this?
那么为此格式化的最佳代码是什么?
Prettier is extracly of you need. Prettier 正是您所需要的。 If you want to personalized format code jsx, you can configuration prettier with your style.
如果你想要个性化的格式代码jsx,你可以根据自己的风格配置prettier。
Finally, I have found a way to do it.最后,我找到了一种方法。 In the vscode settings, I have to change to default format to prettier.
在 vscode 设置中,我必须将默认格式更改为更漂亮。
As well as on the project it is needed to create a.prettierrc file with suitable configurations for the project.除了在项目上,还需要为项目创建一个具有合适配置的 .prettierrc 文件。
{
"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.如果您不需要它,您可以随时启用在没有 .prettierrc 文件的情况下格式化代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.