Bird
Raised Fist0
React Nativemobile~20 mins

Image optimization in React Native - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Image Optimization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate
2:00remaining
Image loading performance in React Native
Which option correctly optimizes image loading to improve app performance in React Native?
React Native
import { Image } from 'react-native';

export default function App() {
  return (
    <Image source={{ uri: 'https://example.com/photo.jpg' }} style={{ width: 100, height: 100 }} />
  );
}
A<Image source={{ uri: 'https://example.com/photo.jpg' }} style={{ width: 100, height: 100 }} resizeMode="contain" />
B<Image source={{ uri: 'https://example.com/photo.jpg' }} style={{ width: 100, height: 100 }} progressiveRenderingEnabled={true} />
C<Image source={{ uri: 'https://example.com/photo.jpg' }} style={{ width: 100, height: 100 }} cache="force-cache" />
D<Image source={{ uri: 'https://example.com/photo.jpg' }} style={{ width: 100, height: 100 }} />
Attempts:
2 left
💡 Hint
Consider props that control image scaling for better rendering performance.
🧠 Conceptual
intermediate
1:30remaining
Best image format for mobile apps
Which image format is generally best for mobile apps to balance quality and file size?
AJPEG
BSVG
CTIFF
DBMP (Bitmap)
Attempts:
2 left
💡 Hint
Consider formats that compress well and are widely supported.
❓ lifecycle
advanced
2:30remaining
Handling image loading errors
What is the correct way to handle an image loading error in React Native to show a fallback image?
React Native
import React, { useState } from 'react';
import { Image } from 'react-native';

export default function App() {
  const [error, setError] = useState(false);
  return (
    <Image
      source={error ? require('./fallback.png') : { uri: 'https://example.com/photo.jpg' }}
      style={{ width: 100, height: 100 }}
      onError={() => setError(true)}
    />
  );
}
AUse onError prop to set error state and switch source to fallback image.
BUse onLoad prop to detect errors and switch source.
CWrap Image in try-catch block to catch loading errors.
DUse a timeout to check if image loaded and then switch source.
Attempts:
2 left
💡 Hint
React Native Image component has a prop for error handling.
🔧 Debug
advanced
2:00remaining
Why does this image not display?
Given this React Native code, why does the image not show on the screen?
React Native
import { Image } from 'react-native';

export default function App() {
  return (
    <Image source={{ uri: 'https://example.com/photo.jpg' }} />
  );
}
AReact Native Image does not support remote images.
BThe URI is invalid and causes a network error.
CImage component requires a resizeMode prop to display.
DMissing width and height styles causes image not to render.
Attempts:
2 left
💡 Hint
Think about what React Native needs to know to show an image size.
❓ navigation
expert
3:00remaining
Optimizing image-heavy screen navigation
You have a screen with many large images. Which approach best improves navigation speed and memory use in React Native?
ALoad all images at once when the screen mounts.
BPreload all images in a global state before navigation.
CUse FlatList with windowSize and removeClippedSubviews props to load images lazily.
DUse ScrollView with nested Image components for smooth scrolling.
Attempts:
2 left
💡 Hint
Think about how to load only visible images to save memory.

Practice

(1/5)
1. What is the main benefit of optimizing images in a React Native app?
easy
A. It increases the app's file size
B. It changes the app's background color
C. It adds animations to images automatically
D. It makes the app load faster and use less data

Solution

  1. Step 1: Understand image optimization purpose

    Optimizing images reduces their size and improves loading speed.
  2. Step 2: Identify the benefit in app performance

    Smaller images use less data and make the app faster to load.
  3. Final Answer:

    It makes the app load faster and use less data -> Option D
  4. Quick Check:

    Image optimization = faster app and less data [OK]
Hint: Optimized images speed up apps and save data [OK]
Common Mistakes:
  • Thinking optimization changes colors
  • Believing optimization adds animations
  • Assuming optimization increases file size
2. Which of the following is the correct way to set an image's resize mode in React Native?
easy
A. <Image source={uri} resizeMode='zoom' />
B. <Image source={uri} resizeMode='cover' />
C. <Image source={uri} mode='cover' />
D. <Image source={uri} resize='cover' />

Solution

  1. Step 1: Recall correct prop name for resizing

    The correct prop to control image resizing is resizeMode.
  2. Step 2: Check valid resizeMode values

    Valid values include 'cover', 'contain', 'stretch', but not 'zoom'.
  3. Final Answer:

    <Image source={uri} resizeMode='cover' /> -> Option B
  4. Quick Check:

    resizeMode='cover' is correct syntax [OK]
Hint: Use resizeMode prop with valid values like 'cover' [OK]
Common Mistakes:
  • Using 'resize' instead of 'resizeMode'
  • Using invalid values like 'zoom'
  • Using 'mode' prop which does not exist
3. What will happen if you use a very large image without resizing in a React Native app?
medium
A. The app may become slow and use more memory
B. The app will load faster because large images are better quality
C. The image will automatically resize to fit the screen
D. The app will crash immediately

Solution

  1. Step 1: Understand impact of large images

    Large images consume more memory and take longer to load.
  2. Step 2: Identify app behavior with large images

    This can slow down the app but usually does not crash it immediately.
  3. Final Answer:

    The app may become slow and use more memory -> Option A
  4. Quick Check:

    Large images = slower app and more memory use [OK]
Hint: Large images slow app and use more memory [OK]
Common Mistakes:
  • Thinking large images load faster
  • Assuming images auto resize always
  • Believing app crashes immediately
4. You wrote this code but the image does not resize as expected:
<Image source={{uri: 'image.png'}} resizeMode='stretch' />

What is the likely mistake?
medium
A. The source prop should be a string, not an object
B. The resizeMode value 'stretch' is invalid
C. The image style is missing width and height
D. The image URI is incorrect

Solution

  1. Step 1: Check image resizing requirements

    In React Native, images need explicit width and height styles to resize properly.
  2. Step 2: Verify code props and values

    The source and resizeMode are correct; missing styles cause no resize effect.
  3. Final Answer:

    The image style is missing width and height -> Option C
  4. Quick Check:

    Missing width/height stops resizing [OK]
Hint: Always set width and height styles for images [OK]
Common Mistakes:
  • Thinking resizeMode 'stretch' is invalid
  • Assuming source must be string only
  • Ignoring need for width and height styles
5. You want to optimize images for different screen sizes in your React Native app. Which approach is best?
hard
A. Use multiple image versions and select with require() based on screen size
B. Use only one large image and rely on resizeMode='contain'
C. Load images from the internet without resizing
D. Use SVG images only, ignoring bitmap formats

Solution

  1. Step 1: Understand responsive image needs

    Different screen sizes need different image resolutions for best quality and performance.
  2. Step 2: Choose best method to handle multiple sizes

    Using multiple image versions and selecting them with require() based on screen size is efficient.
  3. Final Answer:

    Use multiple image versions and select with require() based on screen size -> Option A
  4. Quick Check:

    Multiple versions + require() = best optimization [OK]
Hint: Select image versions by screen size with require() [OK]
Common Mistakes:
  • Using one large image wastes memory
  • Ignoring resizing causes poor quality or slow app
  • Assuming SVG works for all images
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