Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 71 ยท Getting Started

Core Components: View, Text, Image

Learn View, Text, Image and ScrollView, how they map to native widgets, why div and span do not exist, and the rules for nesting text in React Native.

Every React Native screen is built from a small set of core components that React Native provides. They are the equivalent of HTML elements, but they map to native widgets. In this lesson you learn the four you will use most: View, Text, Image and ScrollView. You also learn the rules that trip up almost every web developer on day one, especially where text is allowed to go.

Read-only and stand-in. The react-native imports below cannot run in a browser, so the real components are shown in plain code blocks. The TryIts use a tiny stand-in renderer that maps View, Text and Image to HTML and enforces the same text rule, so you can see the behavior safely.

View: the container

View is the basic building block for layout. It is a rectangle that can hold other components and be styled with a background, borders, padding and Flexbox. On iOS it becomes a UIView; on Android a view group. It is the closest thing to a div.

TSX
import { View, Text } from 'react-native';

export function Card() {
  return (
    <View style={{ padding: 16, backgroundColor: 'white', borderRadius: 12 }}>
      <Text>Inside a card</Text>
    </View>
  );
}

Two differences from a div. First, a View lays out its children with Flexbox by default, in a column. Second, a View cannot hold a loose string. Putting text directly inside it is an error.

Text: all words go here

Text is the only component that can display text. Any string must be a child of a Text (or of a component that renders one).

TSX
// Wrong: a string directly inside View
<View>Hello</View>

// Right
<View>
  <Text>Hello</Text>
</View>

The first form fails at runtime with an error message that says text strings must be rendered within a <Text> component. This happens because on native platforms, text is a different kind of view than a container, so React Native needs to know where the text begins.

Nested Text and inheritance

You can put Text inside Text. The inner text inherits the outer text's style, and the pieces flow together as one paragraph. This is how you bold one word inside a sentence:

TSX
<Text style={{ fontSize: 16, color: '#334155' }}>
  Read the <Text style={{ fontWeight: '700' }}>whole</Text> lesson.
</Text>

Style inheritance works only between Text components. A View does not pass text styles to the Text inside it, so a color on a View does nothing to its text. Each Text needs its own style, or a shared component that applies it (you will build one in Building Your First Screen).

Other things to know about Text:

  • Long text wraps by default; numberOfLines truncates it.
  • There is no <h1> or <p>. You create hierarchy with fontSize and fontWeight.
  • Some text components are focusable by a screen reader automatically, which is why you should label things properly (see Accessibility).

The four you use first

View A container. Like a div.
Text Every string lives here.
Image Local or remote pictures.
ScrollView Content taller than the screen.
1 / 2

Image

Image shows a picture. A bundled file is loaded with require; a remote file is described by an object with a uri:

TSX
import { Image } from 'react-native';

// Local file, size taken from the file
<Image source={require('./assets/logo.png')} style={{ width: 96, height: 96 }} />

// Remote file: you must give a size yourself
<Image
  source={{ uri: 'https://example.com/photo.jpg' }}
  style={{ width: 200, height: 120 }}
  alt="A mountain lake at sunrise"
/>

For remote images React Native cannot know the size before it downloads the file, so you must set width and height in the style (or a size plus aspectRatio). Without a size the image is invisible, which is a very common first mistake. The alt prop gives screen readers a description. There is much more to cover (resize modes, caching, placeholders), and it comes later in Images, Icons and Media.

ScrollView

A screen does not scroll by itself. If your content is taller than the screen, wrap it in a ScrollView:

TSX
import { ScrollView, Text } from 'react-native';

export function Article() {
  return (
    <ScrollView contentContainerStyle={{ padding: 16, gap: 12 }}>
      <Text>Paragraph one...</Text>
      <Text>Paragraph two...</Text>
      {/* many more */}
    </ScrollView>
  );
}

ScrollView renders all of its children at once, even those far off screen. That is perfect for a settings screen or an article, and wasteful for a list of a thousand items. For long lists you will use FlatList in FlatList Essentials. The style prop styles the scroll area itself; contentContainerStyle styles the content inside it (padding and gaps belong there).

A stand-in renderer

The example below defines View, Text and Image as small components that render HTML and enforce the text rule. The error boundary catches the mistake and shows the message, as the real app would (a red box in development).

A View/Text renderer with the text rule

The first screen renders; the second one throws the same kind of error you will see on a real device. (When an error is caught by a boundary React also logs it to the console, which this page keeps quiet.)

Text inheritance in practice

In the stand-in, nested Text becomes nested span elements, which inherit styles through CSS. On a device the inheritance is implemented by React Native itself. The result is the same, and so is the limit: a parent View never hands its text style to children.

Inheritance: Text yes, View no

The first case receives the red color and the size; the second only keeps its own weight. If you want shared text styling across a screen, put it in a reusable Text wrapper component.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What happens if you write <View>Hello</View> in React Native?

    A View is a container, and a bare string is not allowed in it. Wrap the string in <Text>.
  2. 2. A parent View sets color: 'red'. What color is the Text inside it?

    There is no CSS cascade. Only nested Text components inherit text styles from their Text parents.
  3. 3. Why might a remote Image not appear at all?

    React Native does not know a remote image's size in advance, so without width and height (or an aspect ratio) there is nothing to draw.
  4. 4. When should you prefer FlatList over ScrollView?

    ScrollView mounts all children. FlatList renders only what is near the screen, which saves memory and time on long lists.

Summary

  • View is the container, Text holds every string, Image shows pictures and ScrollView scrolls content that does not fit.
  • There is no div, span, p or img. These components map to native widgets.
  • A bare string inside View is an error; text must be in Text.
  • Nested Text inherits styles from its Text parents, but a View passes nothing down.
  • Remote images need an explicit size; ScrollView renders all its children, so use FlatList for long lists.

Next, put these pieces together in Building Your First Screen.