简体   繁体   English

React Prettier - 如何删除字符串的支撑括号

[英]React Prettier - how to remove the prop brackets for string

I have this component.我有这个组件。

<ComponentA text='Text A'/>

When I save the file, the prettier will update the code to当我保存文件时,prettier 会将代码更新为

<ComponentA text={'Text A'}/>

How can I disable this behaviour in prettier?如何在更漂亮的情况下禁用此行为?

I don't think there is a proper way around this issue.我不认为有解决这个问题的正确方法。 The issue thread on Github was closed without a resolution. Github 上的问题线程在没有解决方案的情况下关闭。 However, there are few workarounds但是,解决方法很少


1.. Manually tell prettier to ignore line 1..手动告诉prettier忽略行

You can use {/* prettier-ignore */} above each component where you want the prettier to ignore/skip formatting.您可以在希望 prettier 忽略/跳过格式的每个组件上方使用{/* prettier-ignore */} (Opinion: Its very time-consuming and not scalable) (意见:它非常耗时且不可扩展)


2.. Change the config 2..更改配置

On the prettier config file, add below在更漂亮的配置文件上,添加以下内容

jsxBracketSameLine: false

By default, this rule will check for and warn about unnecessary curly braces in both JSX props and children.默认情况下,此规则将检查 JSX 道具和子项中不必要的花括号并发出警告。 For the sake of backwards compatibility, prop values that are JSX elements are not considered by default.为了向后兼容,默认情况下不考虑作为 JSX 元素的 prop 值。 Details here 详情在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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