question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow usage of "className"

See original GitHub issue

Hi, 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>

[0] http://tachyons.io/docs/

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
satya164commented, Apr 26, 2016

@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 the styles 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.

<View style={[ s.h100, s.w100, dark ? s.bgBlack : null ]}>
   <Text style={[ s.w100, s.bgWhite ]} />
</View>

BTW, you can’t use - in a JavaScript object key unless you quote it.

1reaction
fab1ancommented, Apr 26, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found