Why use StyleSheet.create?

0

Why use StyleSheet.create ? When starting a new project ( react-native init test , the project comes with style as follows.

const styles = StyleSheet.create({
  container: {

  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
  Imagem: {
    resizeMode: 'contain',
    width: 50,
    height: 50
  }
});

But if I do the following, style will work the same way, so what's the difference?

const styles = {
  container: {

  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
  Imagem: {
    resizeMode: 'contain',
    width: 50,
    height: 50
  }
}
    
asked by anonymous 16.02.2018 / 15:30

1 answer

1

I think it's best to use StyleSheet whenever possible because you'll have more performance than just using common objects.

Quote from the React documentation:

  

Creating a stylesheet from a style object ( Stylesheet ) makes it possible to refer to it by ID instead of creating a new style object every time.

     

It ( Stylesheet ) also allows you to submit the style only once. All subsequent uses will forward an id (not implemented yet).

I hope it helps!

    
16.02.2018 / 15:55