React Native

How do you style components in React Native?

Easy
38
Added
In React Native, you can style components using the StyleSheet API or inline styles.

Solution Code

React Native
-- Example Code --
import React from "react";
import { View, Text, StyleSheet } from "react-native";

const App = () => {
  return (
    <View style={styles.container}>
      <Text style={styles.text}>Styled Text</Text>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#f5fcff",
  },
  text: {
    fontSize: 20,
    textAlign: "center",
    margin: 10,
  },
});

export default App;
Explanation
This code demonstrates how to use the StyleSheet API to style components.

Guided Hints

{'hint': 'Use the StyleSheet API for reusable styles.'}
{'hint': 'Inline styles can be used for quick styling.'}