0

I've been having some problems with figuring out how to import an image dynamically in react. After some research, I learned that the require() function is needed, so this is what I have tried so far:

<img src={require(`../../assets/${companyName}.png`)}></img>

But my web page is still producing a blank image. Is there any guidance or tips I can receive on this? I am using the create-react-app build for reference. Thanks so much in advance!

1 Answers1

0

It seems like you're importing your image as:

import companyName from '../../assets/companyName.png'

Try to add it like this:

<img src={companyName} alt=''/>
Uria Levi
  • 258
  • 1
  • 11
  • i want to retrieve an image using a dynamic image path. the image is already uploaded locally and want to retrieve it dynamically – soapysoap Feb 12 '21 at 00:59
  • try this: https://stackoverflow.com/questions/54311204/how-to-do-dynamic-images-in-reactjs – Uria Levi Feb 12 '21 at 08:10