0
0
React Nativemobile~20 mins

Image component (local and remote) in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Image Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What will this React Native Image component display?
Consider this code snippet in a React Native app:
import React from 'react';
import { Image } from 'react-native';

export default function App() {
  return (
    
  );
}

What will the user see when this runs?
React Native
import React from 'react';
import { Image } from 'react-native';

export default function App() {
  return (
    <Image
      source={{ uri: 'https://example.com/image.png' }}
      style={{ width: 100, height: 100 }}
      accessibilityLabel="Example remote image"
    />
  );
}
AAn error because the source prop must be a local file path string.
BA blank space because local images require a different source format.
CA 100x100 pixel image loaded from the internet at the given URL.
DA 100x100 pixel placeholder image bundled with the app.
Attempts:
2 left
💡 Hint
Think about how React Native loads images from URLs using the uri property.
📝 Syntax
intermediate
2:00remaining
Which option correctly loads a local image in React Native?
You want to display a local image named 'logo.png' stored in your project's 'assets' folder. Which code snippet correctly loads this image?
A<Image source={require('./assets/logo.png')} style={{width: 50, height: 50}} />
B<Image source={{ uri: './assets/logo.png' }} style={{width: 50, height: 50}} />
C<Image source='./assets/logo.png' style={{width: 50, height: 50}} />
D<Image src={require('./assets/logo.png')} style={{width: 50, height: 50}} />
Attempts:
2 left
💡 Hint
Local images require the require() function in React Native.
lifecycle
advanced
2:00remaining
What happens if the remote image URL is invalid or unreachable?
In React Native, if you use an Image component with a remote URL that does not exist or the device is offline, what will happen?
AThe Image component will show nothing (empty space) where the image should be.
BThe app will crash with a network error.
CThe Image component will automatically show a default placeholder image.
DThe Image component will display the last cached image even if the URL is unreachable.
Attempts:
2 left
💡 Hint
Think about what React Native does when it cannot load an image from the internet.
🧠 Conceptual
advanced
2:00remaining
Why is it important to set width and height on Image components in React Native?
In React Native, what is the main reason you must specify width and height styles on Image components?
ABecause without width and height, the image will not display at all.
BBecause width and height control the image file size and quality.
CBecause accessibility tools require width and height to describe images.
DBecause React Native needs explicit size to allocate layout space and avoid layout jumps.
Attempts:
2 left
💡 Hint
Think about how layout works in mobile apps and how images affect it.
🔧 Debug
expert
2:00remaining
Why does this local image fail to display in React Native?
You wrote this code to display a local image:
import React from 'react';
import { Image } from 'react-native';

export default function App() {
  return (
    
  );
}

But the image does not show. What is the cause?
React Native
import React from 'react';
import { Image } from 'react-native';

export default function App() {
  return (
    <Image source={{ uri: './assets/icon.png' }} style={{ width: 40, height: 40 }} />
  );
}
AThe style width and height are too small to display the image.
BUsing uri with a relative local path does not work; local images must use require().
CThe Image component requires an absolute file path for local images.
DThe Image component cannot load PNG files locally.
Attempts:
2 left
💡 Hint
Check how local images are loaded differently from remote images in React Native.