Skip to content
tezvyn:
Menu

React Native's Image Component

Source: reactnative.devEasyHow cards are made

The Image component is React Native's tool for displaying pictures from network URLs, local app assets, or the device's camera roll. The biggest footgun: you must manually set width and height for any image loaded from a URL or it won't appear.

Why it exists

Mobile apps need a performant way to display images from different sources, like the network or local files. React Native abstracts the platform-specific image views (like UIImageView on iOS and Fresco on Android) into a single, cross-platform component, simplifying development.

The mental model

Think of the Image component as a specialized View designed for one job: rendering a picture. It handles the underlying complexity of fetching remote images, decoding them, and displaying them, while giving you hooks to manage loading states and presentation.

How it works

You provide a source prop to tell the component where to find the image. For static assets bundled with your app, you use require('./path/to/image.png'). For network images, you provide an object: { uri: 'https://...' }. Because React Native can't know the dimensions of a remote image before downloading it, you must provide an explicit width and height in the style prop for network images. The component then uses the native platform's image-loading library to fetch, cache, and display the image.

When to use it

Use this component whenever you need to display a raster image (like a PNG or JPG). This includes user avatars from an API, icons bundled with your app, photos from the camera roll, or background images (using the related ImageBackground component). It's also useful for showing placeholders or loading indicators while the main image downloads, using props like defaultSource or loadingIndicatorSource.

When not to use it

For simple vector graphics or icons, a library like react-native-vector-icons might be a better choice. It uses font files or SVG, which can be scaled and colored more easily than static images. For complex background effects that involve more than a single image, a custom View with other child elements might be more flexible.

One canonical example

A classic use case is displaying a logo from a URL. You pass an object to the source prop with a uri key pointing to the image's web address. Crucially, you must also provide a style prop with explicit width and height values. Without these styles, the image will have zero dimensions and be invisible on the screen.

Interview question

When displaying an image from a network URL using React Native's Image component, which of the following is a critical requirement for the image to be visible?

  • a.You must specify explicit width and height in the style prop.Correct
  • b.The source prop must include a headers object for authentication.
  • c.It must be wrapped within a View component that defines its layout.
  • d.The image must be pre-cached on the device for optimal performance.
Why?

The card explicitly states that for network images, 'you must provide an explicit width and height in the style prop' because React Native cannot know remote image dimensions, and 'Without these styles, the image will have zero dimensions and be invisible'. While wrapping in a View (C) is common for layout, the Image component itself needs the dimensions to render a network image.

Just read this? Test yourself on what you have been reading.

Read the original → reactnative.dev

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on react-native — each one lists the topics its interview covers.

See open roles