Mudassir Zakaria
Mudassir Zakaria

Reputation: 437

React Native load image dynamically

Is there any way to load an image this way?

var x = './img/a.jpg';
<Image source={require(x)}/>

I need to use this because I want to load the image dynamically.

Upvotes: 0

Views: 313

Answers (1)

Orgil
Orgil

Reputation: 711

Simply you can create object and use it as follows

const images = {
  foo: require('./img1.png'),
  bar: require('./img2.png'),
}

<Image source={images.foo} />

Upvotes: 1

Related Questions