Allow usage of "className"
See original GitHub issueHi, I use tachyons [0] to style react for web, so I’d like to use the className
property in react-native as well.
It allows me to use “mini”-css classes and write code like this, instead of using the styles
property, which I find way better (after having tried both approaches).
<View className="w1 wv">
</View>
Issue Analytics
- State:
- Created 7 years ago
- Comments:16 (2 by maintainers)
Top Results From Across the Web
Why React uses className over class attribute
Explanation: The only reason behind the fact that it uses className over class is that the class is a reserved keyword in JavaScript...
Read more >Passing in class names to react components - Stack Overflow
In React, when you want to pass an interpreted expression, you have to open a pair of curly braces. Try: render () {...
Read more >Applying React Conditional classNames - Pluralsight
Depending on your preferences and needs, you can apply conditional classNames with a ternary or with a library.
Read more >Element.className - Web APIs | MDN
The className property of the Element interface gets and sets the value of the class attribute of the specified element.
Read more >Why does React use className instead of a class attribute?
When applying CSS classes to all common DOM and SVG elements like buttons, li, a, and div in React, we use the className...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@fab1an No. React Native doesn’t support this pattern. To support this at runtime, you’ll have to implement a
className
prop in every component that wants to support this and you also need a reference to thestyles
object to extract the styles out from it. Also conditionally applying style is much messier with this approach.Why not just use this? It doesn’t look that different to me. Also this is more flexible.
BTW, you can’t use
-
in a JavaScript object key unless you quote it.For conditional styles I tend to use the
classnames
library.I didn’t know you could pass an array to style. Maybe I’ll write the babel-transform, but this should work for me in the meantime, thank you.