[英]Styling react components
I'm a big react fan. 我是一个很反应的粉丝。 It's a really awesome tool for building UI but there are some problems which are difficult to get rid of without trouble. 它是构建UI的一个非常棒的工具,但是有些问题很难摆脱而没有麻烦。
One of them is styling components, the original 'react-way' is using inline styles, but this solution has some negative qualities, ex: 其中一个是造型组件,原始的“反应方式”使用内联样式,但这个解决方案有一些负面的品质,例如:
But there are some positive ones: 但有一些积极的:
Other "WriteYourStylesInJS" practices have the same weaknesses, and the biggest is the reduced set of styling tools (Yes, I'm too lazy to write prefixes). 其他“WriteYourStylesInJS”实践具有相同的弱点,最大的是减少的样式工具集(是的,我懒得写前缀)。
As for my actual question, how do you make your react components and css (or scss/sass or less or any other language) styles cohesive? 至于我的实际问题,你如何使你的反应组件和css(或scss / sass或更少或任何其他语言)风格具有凝聚力?
How do you make styles customizable and maintainable? 如何使样式可定制和可维护?
Is my prepossesion against inline styles reasonable? 我对内联样式的预设是否合理?
I'm using inline styles and I had some problems at the beginning but you know what? 我正在使用内联样式,我在开始时遇到了一些问题,但你知道吗? I love it know... 我喜欢它知道......
But you're right and you can have headaches with pseudo selectors like :hover... or vendor prexing, even media queries. 但是你是对的,你可能会对伪选择器感到头疼:像hover ...或供应商prexing,甚至是媒体查询。
So.. if you need all of that, maybe you should check Radium 所以..如果你需要所有这些,也许你应该检查Radium
stay foolish! 保持愚蠢!
In my project, i have used separated css files for styling, with same name like my components. 在我的项目中,我使用了分离的css文件进行样式设置,其名称与我的组件相同。 In production it will be anyway minified and splitted in one js/css file, but you can easily copy/paste your components from project to project. 在生产中,它无论如何都会在一个js / css文件中缩小和分割,但是您可以轻松地将组件从一个项目复制/粘贴到项目中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.