0

I have the following component in react that dinamically loads an image:

<img src {require(getImgPath()).default}/>

This component throws the following error: Cannot find module './images/abc.svg'

If I change the component to the following:

<img src {require(`${getImgPath()}`).default}/>

Then it works. Why is that?

I also tried this without success:

<img src {require(getImgPath().toString()).default}/>
Jöcker
  • 5,281
  • 2
  • 38
  • 44

1 Answers1

-1
 <Image style={{width:"100%",height:75,borderTopRightRadius:6,borderTopLeftRadius:6,marginBottom:5}}
          source={{
            uri: 'https://example.com/'+param.id.toString()+'.jpg',
  }} />

U can use dynamic path with Image component.