0
0
React Nativemobile~20 mins

Image optimization in React Native - Practice Problems & Coding Challenges

Choose your learning style9 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.