Reputation: 437
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
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