Lesson 13 of 60 – Text Component in React Native
22%

Text Component in React Native

The Text component is one of the most important components in React Native. It is used to display text such as headings, labels, paragraphs, messages, names and other information on the mobile screen.

Note: In React Native, text should normally be displayed using the Text component. It is different from HTML text elements such as p, h1 and span.

1. What is Text?

Text is a built-in React Native component used to display text content on the screen.

import { Text } from "react-native";

It can display simple text as well as styled and nested text.

2. Importing Text

The Text component is imported from the react-native package.

import { Text } from "react-native";

You can import Text together with other React Native components.

import {
    View,
    Text
} from "react-native";

3. Basic Text Syntax

<Text>
    Hello React Native
</Text>

The text is written between the opening and closing Text tags.

4. Text inside View

Text is commonly placed inside a View.

import {
    View,
    Text
} from "react-native";

export default function App() {

    return (
        <View>

            <Text>
                Welcome to React Native
            </Text>

        </View>
    );
}

5. Displaying a Heading

React Native does not require separate HTML-style heading tags. You can create headings by styling the Text component.

<Text style={{
    fontSize: 28,
    fontWeight: "bold"
}}>
    Student Dashboard
</Text>

6. Text Styling

The style prop is used to change the appearance of text.

<Text style={styles.title}>
    Hello Student
</Text>
const styles = StyleSheet.create({

    title: {
        fontSize: 24,
        fontWeight: "bold"
    }

});

7. fontSize

The fontSize property controls the size of text.

const styles = StyleSheet.create({

    text: {
        fontSize: 20
    }

});
<Text style={styles.text}>
    React Native
</Text>

8. fontWeight

The fontWeight property controls the thickness of text.

const styles = StyleSheet.create({

    title: {
        fontWeight: "bold"
    }

});

Common values include normal and bold.

9. Text Color

The color property changes the text color.

const styles = StyleSheet.create({

    title: {
        color: "blue",
        fontSize: 24
    }

});
<Text style={styles.title}>
    Welcome
</Text>

10. Text Alignment

The textAlign property controls horizontal text alignment.

const styles = StyleSheet.create({

    title: {
        textAlign: "center"
    }

});

Common values include left, center and right.

11. Text Decoration

The textDecorationLine property can add decoration to text.

const styles = StyleSheet.create({

    text: {
        textDecorationLine: "underline"
    }

});

This can be useful for links and emphasized content.

12. Letter Spacing

The letterSpacing property controls the spacing between characters.

const styles = StyleSheet.create({

    title: {
        letterSpacing: 2
    }

});

13. Line Height

The lineHeight property controls the height of each line of text.

const styles = StyleSheet.create({

    paragraph: {
        fontSize: 16,
        lineHeight: 26
    }

});

It is useful for improving readability in longer text.

14. Text Transform

The textTransform property can change the presentation of text.

const styles = StyleSheet.create({

    title: {
        textTransform: "uppercase"
    }

});

Possible values include uppercase, lowercase and capitalize.

15. Multiple Text Components

A screen can contain multiple Text components.

<View>

    <Text>Student Name</Text>

    <Text>Rahul Kumar</Text>

    <Text>Course: React Native</Text>

</View>

Each Text component can have its own style.

16. Nested Text

Text components can be nested inside other Text components. This is useful when different parts of a sentence need different styles.

<Text>
    Hello
    <Text style={{
        fontWeight: "bold"
    }}>
        Rahul
    </Text>
</Text>

17. Different Styles in One Text

Nested Text allows different parts of the same sentence to use different styles.

<Text>

    Welcome to
    <Text style={{
        fontWeight: "bold"
    }}>
        React Native
    </Text>

</Text>

This technique is useful for highlighted words and labels.

18. Text with Variables

JavaScript variables can be displayed inside Text using curly braces.

const name = "Rahul";

return (
    <Text>
        Hello {name}
    </Text>
);

The output will display Hello Rahul.

19. Text with Expressions

JavaScript expressions can also be used inside Text.

const marks = 80;

return (
    <Text>
        Marks: {marks}
    </Text>
);

Expressions inside curly braces are evaluated by JavaScript.

20. Text with Props

A component can receive text through props.

function Student(props) {

    return (
        <Text>
            Student: {props.name}
        </Text>
    );

}
<Student name="Rahul" />

21. Text with State

Text can display values stored in React state.

import {
    useState
} from "react";

const [name, setName] = useState("Rahul");

return (
    <Text>
        {name}
    </Text>
);

Whenever the state changes, React can update the displayed value.

22. Text in a Card

Text is frequently used inside card-style Views.

<View style={styles.card}>

    <Text style={styles.title}>
        Student Details
    </Text>

    <Text>
        Name: Rahul
    </Text>

    <Text>
        Course: React Native
    </Text>

</View>

23. Text for Buttons

Text is commonly placed inside interactive components such as Pressable.

import {
    Pressable,
    Text
} from "react-native";

<Pressable
    onPress={() => alert("Button Pressed")}
>

    <Text>
        Submit
    </Text>

</Pressable>

24. Text for Error Messages

Text can be used to display validation or error messages.

const styles = StyleSheet.create({

    error: {
        color: "red",
        fontSize: 14
    }

});
<Text style={styles.error}>
    Please enter your name.
</Text>

25. Long Text

Text can contain longer content such as descriptions and instructions.

<Text style={styles.description}>

    React Native allows developers
    to create mobile applications
    using React and JavaScript.

</Text>

For long content, components such as ScrollView can be used when the surrounding screen needs scrolling.

26. Number of Lines

The numberOfLines prop can limit the number of visible lines.

<Text numberOfLines={2}>

    React Native is used to build
    mobile applications for different
    platforms.

</Text>

This can be useful when displaying previews or limited descriptions.

27. Complete Text Example

import {
    View,
    Text,
    StyleSheet
} from "react-native";

export default function App() {

    return (
        <View style={styles.container}>

            <Text style={styles.title}>
                Student Dashboard
            </Text>

            <Text style={styles.name}>
                Rahul Kumar
            </Text>

            <Text style={styles.course}>
                Course: React Native
            </Text>

            <Text style={styles.description}>
                Welcome to the mobile app
                development course.
            </Text>

        </View>
    );
}

const styles = StyleSheet.create({

    container: {
        flex: 1,
        padding: 20,
        justifyContent: "center"
    },

    title: {
        fontSize: 28,
        fontWeight: "bold",
        textAlign: "center"
    },

    name: {
        marginTop: 20,
        fontSize: 22,
        fontWeight: "bold"
    },

    course: {
        marginTop: 10,
        fontSize: 18
    },

    description: {
        marginTop: 15,
        fontSize: 16,
        lineHeight: 24
    }

});

28. Text vs HTML Text Elements

React Native Common Web Equivalent
Text p
Styled Text span
Large Heading Text h1 / h2
Text styling CSS

React Native uses the Text component for displaying text instead of HTML elements.

29. Best Practices for Text

  • Use Text for displaying text content.
  • Use StyleSheet for reusable text styles.
  • Create meaningful styles such as title, subtitle and description.
  • Use readable font sizes.
  • Use appropriate line height for paragraphs.
  • Use nested Text when only part of a sentence needs different styling.
  • Use numberOfLines when a text preview needs a fixed number of lines.
  • Keep text components simple and reusable.

30. Complete Text Workflow

Text
 ↓
Display Content
 ↓
Apply Style
 ↓
Use Variables
 ↓
Use Props
 ↓
Use State
 ↓
Nested Text
 ↓
Interactive Content
 ↓
Complete Mobile Screen

The Text component is fundamental for creating readable mobile interfaces. You will use it throughout your React Native applications for headings, labels, descriptions, messages, buttons and dynamic data.

📌 Key Points

  • Text is used to display text in React Native.
  • It is imported from react-native.
  • Text can be placed inside a View.
  • Text can be styled using the style prop.
  • fontSize controls text size.
  • fontWeight controls text thickness.
  • color changes the text color.
  • textAlign controls text alignment.
  • Text can contain JavaScript variables and expressions.
  • Text can receive dynamic values through props and state.
  • Text components can be nested.
  • numberOfLines can limit displayed lines.

🧠 Quick Quiz

Question: Which React Native component is used to display text on the screen?