我是 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.
linting 规则要求您为颜色使用变量并重复使用它们(关键字主题)。例如。设置一次 textColor
并在所有地方重复使用,然后您只需在一个地方更改它即可更改所有地方的文本颜色。
关于css - React Native 中的颜色文字有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64187517/