css - React Native 中的颜色文字有什么问题?

标签 css reactjs react-native eslint

我是 React Native 的新手,在设置我的 eslint 配置时,我开始看到如下行的错误:

color: '#413C44', --> 颜色文字 ... (react-native/no-color-literals)

我开始禁用它,但这似乎是一个流行的规则。我没有在网上看到关于为什么 React Native 中的颜色文字是一件坏事的解释。有谁知道为什么吗?

最佳答案

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.

https://github.com/Intellicode/eslint-plugin-react-native/blob/master/docs/rules/no-color-literals.md

linting 规则要求您为颜色使用变量并重复使用它们(关键字主题)。例如。设置一次 textColor 并在所有地方重复使用,然后您只需在一个地方更改它即可更改所有地方的文本颜色。

关于css - React Native 中的颜色文字有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64187517/

相关文章:

ios - 使用 use_native_modules react Native Pod 问题

css - 如何将 TTF 文件转换为 OTF 格式?

php - WordPress <?php body_class(); ?> 问题

ipad - 在 UIWebView 中运行 HTML5/CSS3

javascript - 可以在基于数组的循环中创建 useState 吗?

reactjs - 如何在React测试库中为Select Box onChange方法编写测试用例?

javascript - 使用 audio.play() 函数时 react 错误

html - 用于打印 HTML 的不同页面方向

android - 在 React Native 中设置安卓闹钟

react-native - react 导航 - TabNavigator-> StackNavigator 中标题菜单图标的 DrawerNavigator