Bird
Raised Fist0
React Nativemobile~5 mins

Image component (local and remote) in React Native

Choose your learning style10 modes available
Introduction

Images make apps look nice and help users understand content better. The Image component shows pictures from your phone or the internet.

Show a logo stored inside your app files.
Display a user's profile picture from a web address.
Add decorative pictures to make your app more colorful.
Show product images loaded from an online store.
Syntax
React Native
import { Image } from 'react-native';

<Image source={require('./path/to/image.png')} />

<Image source={{ uri: 'https://example.com/image.jpg' }} />

Use require() for local images inside your project.

Use an object with uri for images from the internet.

Examples
This shows a local image called logo.png with size 100x100 pixels.
React Native
import { Image } from 'react-native';

<Image source={require('./assets/logo.png')} style={{ width: 100, height: 100 }} />
This loads a small image from the internet and shows it at 50x50 pixels.
React Native
import { Image } from 'react-native';

<Image source={{ uri: 'https://reactnative.dev/img/tiny_logo.png' }} style={{ width: 50, height: 50 }} />
Sample App

This app shows two images stacked vertically in the center: one local image and one remote image. Both images are 100x100 pixels with some space around them.

React Native
import React from 'react';
import { View, Image, StyleSheet } from 'react-native';

export default function App() {
  return (
    <View style={styles.container}>
      <Image source={require('./assets/local-image.png')} style={styles.image} accessibilityLabel="Local image example" />
      <Image source={{ uri: 'https://reactnative.dev/img/tiny_logo.png' }} style={styles.image} accessibilityLabel="Remote image example" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#fff'
  },
  image: {
    width: 100,
    height: 100,
    margin: 10
  }
});
OutputSuccess
Important Notes

Always set width and height styles for images to display them correctly.

Use accessibilityLabel to describe images for screen readers.

Remote images need internet connection to load.

Summary

The Image component shows pictures from local files or the internet.

Use require() for local images and { uri: 'URL' } for remote images.

Always give images size and accessibility labels.

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