Let's get things started by figuring out how to load images. You can render the <Image> component and pass it properties just like any other React component. But this particular component needs image blob data to be of any use. Let's look at some code:
import React from 'react';
import PropTypes from 'prop-types';
import { View, Image } from 'react-native';
import styles from './styles';
// Renders two "<Image>" components, passing the
// properties of this component to the "source"
// property of each image.
const LoadingImages = ({ reactSource, relaySource }) => (
<View style={styles.container}>
<Image style={styles.image} source={reactSource} />
<Image style={styles.image} source={relaySource} />
</View>
);
// The "source" property can be either
// an object with a "uri" string, or a number
// represending a local "require()" resource.
const sourceProp = PropTypes.oneOfType([
PropTypes.shape({
uri: PropTypes.string.isRequired
}),
PropTypes.number
]).isRequired;
LoadingImages.propTypes = {
reactSource: sourceProp,
relaySource: sourceProp
};
LoadingImages.defaultProps = {
// The "reactSource" image comes from a remote
// location.
reactSource: {
uri:
'https://facebook.github.io/react-native/docs/assets/favicon.png'
},
// The "relaySource" image comes from a local
// source.
relaySource: require('./images/relay.png')
};
export default LoadingImages;
There are two ways to load the blob data into an <Image> component. The first approach loads the image data from the network. This is done by passing an object with a uri property to source. The second <Image> component in this example is using a local image file, by calling require() and passing the result to source.
Take a look at the sourceProp property type validator. This gives you an idea of what can be passed to the source property. It's either an object with a uri string property or a number. It expects a number because require() returns a number.
Now, let's see what the rendered result looks like as follows:

Here's the style that was used with these images:
image: {
width: 100,
height: 100,
margin: 20,
},
Note that without width and height style properties, images will not render. In the next section, you'll learn how image resizing works when width and height values are set.