Why should I use my own StyleSheet React?

Why should I use this:

const styles = StyleSheet.create({
    ...
});

instead of this:

const styles = {
    ...
};

The properties that StyleSheet provides are not really needed for me.

+4
source share
1 answer

The main advantages seem to be related to performance :

Creating a style sheet from a style object allows you to reference it by ID instead of creating a new style object each time.

It also allows you to send style only once across the bridge. All subsequent use will refer to id (not yet implemented).

Other benefits may include:

  • prop is absoluteFillused for

    create overlays with absolute and zero position positioning

    and

  • flattenwhich

    .

: https://facebook.imtqy.com/react-native/docs/stylesheet.html

, , ( , StyleSheet) , .

JavaScript-. , , , . - , .

: http://facebook.imtqy.com/react-native/docs/style.html#content

, , StyleSheet.

, StyleSheet, , , styles.myNiceComponent.backgroundColor === 'blue'

: -?

+9

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


All Articles