Code Monkey home page Code Monkey logo

Comments (6)

thabti avatar thabti commented on July 20, 2024 2

you can do <Text style={styles.['class-name']}> ? while the syntax isn't pretty, it's common way to handle dashes.

@alexmick thoughts?

from react-native-css.

thabti avatar thabti commented on July 20, 2024

@abeikverdi This project is a community and is open source, we accept pull requests. Can I get a more details, like code examples?

from react-native-css.

abeikverdi avatar abeikverdi commented on July 20, 2024

Lets say we have a css like this:

.class-name {
    attribute1: attribute1;
    attribute2: attribute2;
}

The result after using react-native-css would be :

const styles = StyleSheet.create({
    'class-name': {
    attribute1: 'attribute1';
    attribute2: 'attribute2';
  }

And after you assign this to an element in React like this example:

<Text style={styles.class-name}>

I assume RN takes class and name as two classes instead of one class and creates an error.

from react-native-css.

abeikverdi avatar abeikverdi commented on July 20, 2024

I am not sure how this library should convert css classes with dash. Perhaps a class rename?

from react-native-css.

alexmick avatar alexmick commented on July 20, 2024

Indeed, the plugin does not rewrite your class names so if you call your class class-name you have to call it by styles['class-name'] as @sabeurthabti pointed out.
The way around this is to camelCase you classes like so

.className {
    attribute1: attribute1;
    attribute2: attribute2;
}

Maybe we could force camelCasing of class names but I have a feeling this would be a confusing behaviour...

PS: I edited your comment @abeikverdi to add the quotes around class-name in the second snippet because this is what react-native-css will output (I just checked)

from react-native-css.

abeikverdi avatar abeikverdi commented on July 20, 2024

@sabeurthabti Ah I see. Didnt know that I can put the classes inside brackets like that. @alexmick I agree it could be confusing.
Cheers

from react-native-css.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.