View, Text and Image
You'll learn the three building blocks of every phone screen, a box, words and a picture, and how they nest.
View, Text and Image placed inside each other.Watch & read
Start with the required ones. The others are there when you need them.
Explanation
You want the top of your habit tracker to show a small logo, the title "My habits" and a line that says
"3 habits today". On the web you would reach for <div>, <h1>, <p> and <img>. On a phone you have
three building blocks instead.
Think of a tiffin carrier. The carrier and its boxes hold things and decide where they sit. That is a
View. The label you write on a box is Text. A photo stuck on the lid is an Image. Boxes can sit
inside boxes, which is called nesting.
<View><Image source={{ uri: "https://reactnative.dev/img/tiny_logo.png" }} style={{ width: 48, height: 48 }} /><Text>My habits</Text><Text>3 habits today</Text></View>
Viewis a box. It draws nothing by itself until you give it a style, like a background colour.Textis the only place words can go. Text insideTextis fine:<Text>Streak: <Text>5 days</Text></Text>.Imageneeds asource. A picture from the internet is{ uri: "https://..." }. A picture in your project isrequire("./assets/logo.png").
People often put words straight inside a View. On a phone that is a red error screen: "Text strings
must be rendered within a <Text> component". Wrap the words in <Text>. The other common one: an
Image from the internet with no width and height shows nothing at all. React Native can't know its
size before it downloads, so you must give one.
Expo also has its own expo-image package, which the official tutorial uses. It works the same way, with a
source and a size, and adds extras like caching. Start with the core Image.
When you read a screen, read the JSX like an outline: every View is a box, and what's inside it is
indented one step. Then find every word and check it sits inside a Text.
Code tour
Click a line number with a ring to read the note for that line.
Practice
Short drills. Take your time and read the code before you answer.
1export default function App() {2 return (3 <View style={{ flex: 1, justifyContent: "center" }}>4 <Text>Drink water</Text>5 Read 10 pages6 </View>7 );8}9// You open this app on your phone in Expo Go.
1import { Image, StyleSheet, Text, View } from "react-native";23export default function App() {4 return (5 <View style={styles.screen}>6 <View style={styles.header}>
Runs in the browser. Choose “My Device” in Snack to try it on your phone with Expo Go.
Quick check
3 questions. Each one explains itself after you answer.
- 1 / 3What is a
Viewfor? - 2 / 3
<Image source={{ uri: "https://example.com/cat.png" }} />shows nothing. What is the most likely fix? - 3 / 3How do you show a picture saved in your project at
assets/logo.png?