3

I'm working on rendering an Image in react native depending on the props passed in.

When I give the image source a direct path the image renders fine on the screen

ie:

<Image
    source={require('../assets/denver.png')}
    style={teamImg}
 />

However if I use string interpolation to render the image based on props I see the following error message:

// props.img = 'denver'
<Image
    source={require(`../assets/${props.img}.png`)}
    style={teamImg}
 />

Requiring unknown module "../assets/denver.png". If you are sure the module is there, try restarting the packager or running "npm" install

How can I render the image so it finds a static image in my directory based on props?

Onaracs
  • 935
  • 3
  • 14
  • 22

0 Answers0