0

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.

Chris
  • 112,704
  • 77
  • 249
  • 231
Mudassir Zakaria
  • 367
  • 4
  • 15
  • Are you using any package manager such as Webpack ? (This is a yes if you are using `create-react-app`) – 3Dos Dec 13 '17 at 13:06

1 Answers1

1

Simply you can create object and use it as follows

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

<Image source={images.foo} />
Orgil
  • 611
  • 7
  • 16