Load image passed as props react native

As the React Native Documentation says, all your images sources need to be loaded before compiling your bundle.

Adding a simple image in React Native should be like this:

<Image source={require('./path_to_your_image.png')} />

Let's say you have this:

const slides = {
  car: './car.png',
  phone: '../phone.png',
}

Then you pass slides as a parameter but still, you won't be able to use it like this (even though logically should work):

<Image source={require(props.car)} />

Use require() inside the sildes{}

const slides = {
  car: require('./car.png'),
  phone: require('../phone.png'),
}

And then use it like this:

<Image source={props.car}/>

your source is wrong.

It should use uri properties.

Either you use require:

<Image source={require('.../../images/logout.png')} />

in turn, you can then require this prop too

<Image source={require(props.imageUri)} />

Or you use the Uri as is:

<Image source={{uri: props.imageUri }} />

Refer to the documentation for more details here

Tags:

React Native