Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Why dont use styleSheet.create in styling screen? #317

Open
viralS-tuanlv opened this issue Feb 21, 2020 · 3 comments
Open

Why dont use styleSheet.create in styling screen? #317

viralS-tuanlv opened this issue Feb 21, 2020 · 3 comments

Comments

@viralS-tuanlv
Copy link

Hi team, i saw the project generated by ignite bowser use style like:

const CONTAINER: ViewStyle = {
  backgroundColor: color.transparent,
...
}

Its perfomance not better than:

const styles = StyleSheet.create({
  container: {
    backgroundColor: color.transparent,
...
  },
});

So why we dont use StyleSheet?

@vantuan88291
Copy link

Ok, no one reply. And i found the result: at rn 0.57 or bellow, we should use StyleSheet for improve perfomance. But now from 0.6x no diffirent between create style using plain object and StyleSheet. So still use plain object.
Reference: https://stackoverflow.com/questions/38958888/react-native-what-is-the-benefit-of-using-stylesheet-vs-a-plain-object

@hedgerh
Copy link

hedgerh commented Feb 29, 2020

Thanks for the followup. I was wondering that myself.

@harrisrobin
Copy link
Contributor

Hi team, i saw the project generated by ignite bowser use style like:

const CONTAINER: ViewStyle = {
  backgroundColor: color.transparent,
...
}

Its perfomance not better than:

const styles = StyleSheet.create({
  container: {
    backgroundColor: color.transparent,
...
  },
});

So why we dont use StyleSheet?

As @vantuan88291 mentioned, there is no performance benefit to using the Stylesheet API. The reason we don't use it is because we find that it is more verbose to type.

It's much easier to type a style object like this:

const CONTAINER: ViewStyle = {
  ...styles
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants