0
0
React Nativemobile~5 mins

Image component (local and remote) in React Native - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the React Native Image component used for?
The Image component displays pictures in your app. It can show images stored locally or loaded from the internet.
Click to reveal answer
beginner
How do you load a local image in React Native?
Use require('./path/to/image.png') inside the source prop of Image. This tells React Native to bundle the image with the app.
Click to reveal answer
beginner
How do you load a remote image from the internet in React Native?
Set the source prop to an object with a uri key, like { uri: 'https://example.com/image.png' }.
Click to reveal answer
beginner
Why should you always set width and height on an Image component?
Without width and height, the image might not show or layout correctly. These tell React Native how much space to reserve for the image.
Click to reveal answer
beginner
What is a simple way to make an image accessible in React Native?
Add the accessibilityLabel prop with a short description of the image. This helps screen readers describe the image to users.
Click to reveal answer
How do you specify a local image in React Native's Image component?
Asource={require('./image.png')}
Bsource={'./image.png'}
Csource={{uri: './image.png'}}
Dsource='./image.png'
Which prop is used to load an image from a URL?
Asource={{uri: 'https://example.com/image.png'}}
Burl='https://example.com/image.png'
Csrc='https://example.com/image.png'
Dpath='https://example.com/image.png'
What happens if you don't set width and height on an Image?
AThe app will crash
BThe image will automatically fill the screen
CThe image will be invisible but take space
DThe image might not display or layout properly
How can you make an image accessible for screen readers?
AAdd alt prop like in HTML
BAdd accessibilityLabel prop with a description
CWrap image in a <Text> component
DNo need, images are accessible by default
Which of these is a valid way to import a local image?
Aconst img = './assets/pic.png';
Bimport img from './assets/pic.png';
Cconst img = require('./assets/pic.png');
Dconst img = new Image('./assets/pic.png');
Explain how to display both a local and a remote image using React Native's Image component.
Think about how you tell React Native where to find the image.
You got /4 concepts.
    Describe why accessibility is important for images and how to add it in React Native.
    Imagine a friend who cannot see the screen well.
    You got /4 concepts.