W
W
warchant2016-01-23 22:00:55
React
warchant, 2016-01-23 22:00:55

Why use StyleSheet.create() in React Native?

Why use StyleSheet.create(...) when you can do without it?
What's the difference between

<View style={styles.container}>
...
</View>
var styles = {
    container: {
        // some styles
    }
};

and
<View style={styles.container}>
...
</View>
var styles = StyleSheet.create({
    container: {
        // some styles
    }
});

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
greenais, 2017-01-06
@greenais

Also asked this question.
Did you manage to find out, if not a secret?

H
Hirurgo, 2018-01-24
@Hirurgo

The line from the documentation says that then you won't create
a new style object every time. Making a stylesheet from a style object makes it possible to refer to it by ID instead of creating a new style object every time.
https://facebook.github.io/react-native/docs/style...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question