[英]How do I configure Prettier format usable React code?
So I started learning React from this ( https://youtu.be/Dorf8i6lCuk?t=1946 ) tutorial and got stuck trying to save a file.所以我开始从这个 ( https://youtu.be/Dorf8i6lCuk?t=1946 ) 教程中学习 React,但在尝试保存文件时遇到了困难。 The video recommends getting prettier and I did and then when I save the file it auto-formats code into something that doesn't work.
该视频建议变得更漂亮,我做到了,然后当我保存文件时,它会自动将代码格式化为不起作用的内容。 eg:
例如:
as per the suggestion a jsx file:根据建议 jsx 文件:
as per suggestion 2: already in Javascript React:根据建议 2:已经在 Javascript React 中:
As per the suggestion in the solutions:根据解决方案中的建议:
Try going to settings > Extensions > uncheck - Enable/disable checkbox.尝试转到设置 > 扩展 > 取消选中 - 启用/禁用复选框。 Or Remove all together.
或一起删除。
Change code to: (Notice the differences in my code to yours, your div
tags are open and return
does not have the divs
wrapped in ()
.将代码更改为:(注意我的代码与你的不同,你的
div
标签是打开的, return
的divs
没有包含在()
。
function App() {
return (
<div>
Hello!
</div> //this was giving you the error before
)
}
export default App
I'd also double check your version of react that you are running.我还会仔细检查您正在运行的 react 版本。 If the version is different from the Tutorials, this could cause issues.
如果版本与教程不同,这可能会导致问题。
This might help: Prettier's format on save messes up .jsx files这可能会有所帮助: Prettier 的保存格式会弄乱 .jsx 文件
Following @AlexB801 's advice I have fixed the thing.按照@AlexB801 的建议,我已经解决了这个问题。 It turns out you must NOT change the extension to .jsx but only change the formatter.
事实证明,您不能将扩展名更改为 .jsx,而只能更改格式化程序。 Attaching an image.
附上一张图片。 Also another thing to be noted here is that this was not an issue with Prettier.
这里要注意的另一件事是,这不是 Prettier 的问题。 like so:
像这样:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.