Bird
Raised Fist0
React Nativemobile~3 mins

Why Image component (local and remote) in React Native? - Purpose & Use Cases

Choose your learning style10 modes available
The Big Idea

What if adding any picture to your app was as easy as pointing and clicking?

The Scenario

Imagine you want to show pictures in your app. You try to add images by writing long code for each picture, handling files manually, and downloading images yourself.

The Problem

This manual way is slow and tricky. You might forget to load images correctly, or the app crashes if the image URL is wrong. Managing local files and remote images separately makes your code messy and hard to fix.

The Solution

The Image component in React Native makes showing pictures easy. It handles both local files and online images smoothly with simple code. You just tell it where the image is, and it does the rest.

Before vs After
✗ Before
const img = require('./img.png');
// then write complex code to display or fetch images
✓ After
<Image source={require('./img.png')} />
<Image source={{uri: 'https://example.com/pic.jpg'}} />
What It Enables

You can quickly add beautiful pictures from your phone or the internet, making your app lively and engaging without headaches.

Real Life Example

Think of a social media app where users upload photos. Using the Image component, the app shows local photos from the device and remote photos from friends instantly and reliably.

Key Takeaways

Manual image handling is slow and error-prone.

The Image component simplifies showing local and remote pictures.

This makes your app look great with less code and fewer bugs.

Practice

(1/5)
1. Which of the following is the correct way to display a local image in React Native using the Image component?
easy
A.
B.
C.
D.

Solution

  1. Step 1: Understand local image usage

    Local images require the require() function to load the file correctly in React Native.
  2. Step 2: Check the syntax for local images

    The correct syntax uses source={require('path')}, not uri or src attributes.
  3. Final Answer:

    <Image source={require('./assets/photo.png')} /> -> Option C
  4. Quick Check:

    Local images use require() = C [OK]
Hint: Local images always use require() inside source prop [OK]
Common Mistakes:
  • Using uri for local images
  • Using src attribute instead of source
  • Passing string directly without require()
2. Which of the following is the correct syntax to display a remote image from a URL in React Native?
easy
A.
B.
C.
D.

Solution

  1. Step 1: Identify remote image syntax

    Remote images require an object with a uri key inside the source prop.
  2. Step 2: Verify correct object structure

    The correct syntax is source={{ uri: 'URL' }}, not using require or src attributes.
  3. Final Answer:

    <Image source={{ uri: 'https://example.com/image.png' }} /> -> Option D
  4. Quick Check:

    Remote images use source={{ uri: URL }} = D [OK]
Hint: Remote images need source={{ uri: 'URL' }} syntax [OK]
Common Mistakes:
  • Using require() for remote URLs
  • Using src attribute instead of source
  • Passing URL as a string directly to source
3. What will be the result of this React Native code snippet?
import React from 'react';
import { Image } from 'react-native';

export default function App() {
  return (
    <Image source={{ uri: 'https://example.com/pic.jpg' }} style={{ width: 100, height: 100 }} accessibilityLabel="Example image" />
  );
}
medium
A. A 100x100 image loaded from the internet with accessibility label
B. A blank space because remote images are not supported
C. An error because accessibilityLabel is not valid on Image
D. A local image displayed with size 100x100

Solution

  1. Step 1: Analyze the image source

    The source uses a remote URL with uri, so it loads an internet image.
  2. Step 2: Check style and accessibility

    The style sets width and height to 100, and accessibilityLabel is valid for screen readers.
  3. Final Answer:

    A 100x100 image loaded from the internet with accessibility label -> Option A
  4. Quick Check:

    Remote image with size and label = B [OK]
Hint: Remote images need uri and style size to display properly [OK]
Common Mistakes:
  • Forgetting to set width and height style
  • Thinking accessibilityLabel causes error
  • Assuming remote images won't load
4. Identify the error in this React Native code snippet that tries to display a local image:
import React from 'react';
import { Image } from 'react-native';

export default function App() {
  return (
    <Image source="./assets/photo.png" style={{ width: 50, height: 50 }} />
  );
}
medium
A. The style prop must be outside the Image component
B. The source prop should use require() for local images
C. The Image component cannot display local images
D. The width and height must be strings, not numbers

Solution

  1. Step 1: Check source prop for local image

    Local images must use require() inside the source prop, not a string path.
  2. Step 2: Verify style and component usage

    The style prop is correctly placed and numbers for width/height are valid in React Native.
  3. Final Answer:

    The source prop should use require() for local images -> Option B
  4. Quick Check:

    Local images need require() = A [OK]
Hint: Local images must use require() inside source prop [OK]
Common Mistakes:
  • Passing string path directly to source
  • Misplacing style prop
  • Using strings for width/height instead of numbers
5. You want to display a local image and a remote image side by side in React Native. Which code snippet correctly implements this with accessibility labels and proper sizing?
hard
A.
B.
C.
D.

Solution

  1. Step 1: Verify local and remote image sources

    Local images must use require(), remote images use source={{ uri: URL }}.
  2. Step 2: Check layout and accessibility

    Using flexDirection: 'row' places images side by side, and accessibilityLabel is correctly added.
  3. Final Answer:

    Code snippet with require() for local, uri for remote, row layout, and labels -> Option A
  4. Quick Check:

    Local require + remote uri + row layout = A [OK]
Hint: Use require() for local, uri for remote, flexDirection row for side by side [OK]
Common Mistakes:
  • Using string path instead of require() for local images
  • Using uri with local file paths
  • Missing accessibility labels
  • Incorrect flexDirection for horizontal layout
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard