What is the best way to pass styles in React Native?

I wonder how best to go through styles. I understand that when using StyleSheet.create it makes the style once, so it can always be called a number. The corresponding component is as follows:

<Text ellipsizeMode={ ellipsizeMode } numberOfLines={ numberOfLines } style={ [stylesheet.defaultText, styles, fontTypes[type], { color }] } > { children } </Text> 

When I use the inspector, I see that four styles go through the bridge, two of which were from the stylesheet.create file, and the other two are object literals.

Would it be wise to clear an array of styles by deleting empty literals or combining them? I'm not sure how important this is. Does anyone know how styles are transferred from the JS layer to their own layer and how best to solve this?

+5
source share
1 answer

The best way:

  • Create a component for your (if you will use this component, if not just create a stylesheet)

  • Create a stylesheet via:

    const styles = StyleSheet.create ({text: {fontSize: 22}});

    1. import styles into your component or where to use it

import {styles} of './styles';

  1. and use it, for example:

Text <\ Text>

What all.

0
source

Source: https://habr.com/ru/post/1275716/


All Articles