(反应)警告ESLINT(反应本/无彩色)

发布于 2025-01-23 13:52:39 字数 250 浏览 1 评论 0原文

我有这种风格的反应

backgroundColor: 'rgba(0, 0, 0, 0.8)',

,但它给了我这个Eslint警告警告Eslint(React-Native/no-color-Literals)

我尝试了这种样式,但它不起作用

{
  backgroundColor: BLACK,
  opacity: 0.8
}

I have this style in react-native

backgroundColor: 'rgba(0, 0, 0, 0.8)',

but It gives me this eslint warning Warning eslint(react-native/no-color-literals)

I tried this styling but it didn't work

{
  backgroundColor: BLACK,
  opacity: 0.8
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

计㈡愣 2025-01-30 13:52:39

请检查此链接了解警告。

开发UI时,我们经常发现自己在UI中的多个位置重复使用相同的颜色。如果必须更新颜色,则可能必须全面更新它们。因此,最好将颜色定义存储在变量中,而不是将它们在样式中进行硬编码。该规则将检测具有文字(IE字符串)为值的颜色属性。

您可以在ESLINT上禁用此警告,也可以将字符串放入变量中。

const blackOpa80 = 'rgba(0, 0, 0, 0.8)'

进而:

backgroundColor: blackOpa80,

Please check this link to understand the warning.

When developing UIs, we often find ourselves reusing the same colors in multiple places in the UI. If the colors have to be updated, they likely have to be updated across the board. So it's good practice to store the color definitions in variables instead of hardcoding them inside styles. This rule will detect color properties that have literals (ie strings) as values.

You can either disable this warning on eslint or put the string into a variable.

const blackOpa80 = 'rgba(0, 0, 0, 0.8)'

And then:

backgroundColor: blackOpa80,
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文