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.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Mudassir Zakaria
  • 387
  • 4
  • 17
  • 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
  • 691
  • 7
  • 16