11 March 2024

In React Native, you can add multiple styles to one element by passing an array of styles to the style prop.

Source code viewer
  1. import React from 'react';
  2. import { View, Text, StyleSheet } from 'react-native';
  3.  
  4. const MyComponent = () => {
  5. return (
  6. <View style={[styles.container, styles.additionalStyle]}>
  7. <Text style={[styles.text, styles.additionalTextStyle]}>Hello, world!</Text>
  8. </View>
  9. );
  10. };
  11.  
  12. const styles = StyleSheet.create({
  13. container: {
  14. flex: 1,
  15. justifyContent: 'center',
  16. alignItems: 'center',
  17. },
  18. text: {
  19. fontSize: 20,
  20. fontWeight: 'bold',
  21. },
  22. additionalStyle: {
  23. backgroundColor: 'lightblue',
  24. },
  25. additionalTextStyle: {
  26. color: 'red',
  27. },
  28. });
  29.  
  30. export default MyComponent;
Programming Language: ECMAScript