O'Reilly logo

React Native By Example by Richard Kho

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Inline styles

An inline style is one that is defined within the markup of your code. Check this sample out:

class Tasks extends Component {   render () {     return (       <View style = {{ flex: 1, justifyContent: 'center',          alignItems: 'center', backgroundColor: '#F5FCFF'        }}>         <Text style = {{ fontSize: 20, textAlign:            'center', margin: 10 }}>           Welcome to React Native!         </Text>       </View>     )   } } 

In the preceding code, you can see how inline style can create a very convoluted and confusing mess, especially when there are several style properties that we want to apply to each component. It's not practical for us to write our styles like this in a large-scale application, so let's break apart the styles into a StyleSheet object.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required