Skip to main content

StyleSheet

A StyleSheet is an abstraction similar to CSS StyleSheets.

Code quality tips:

  • By moving styles away from the render function, you're making the code easier to understand.
  • Naming the styles is a good way to add meaning to the low level components in the render function, and encourage reuse.
  • In most IDEs, using StyleSheet.create() will offer static type checking and suggestions to help you write valid styles.

Reference

Methods​

compose()​

React TSX
static compose(style1: Object, style2: Object): Object | Object[];

Combines two styles such that style2 will override any styles in style1. If either style is falsy, the other one is returned without allocating an array, saving allocations and maintaining reference equality for PureComponent checks.


create()​

React TSX
static create(styles: Object extends Record<string, ViewStyle | ImageStyle | TextStyle>): Object;

An identity function for creating styles. The main practical benefit of creating styles inside StyleSheet.create() is static type checking against native style properties.


flatten()​

React TSX