0

I'm currently making a React application where you can find drink recipes. All the drink recipes are located in a MongoDB. When I GET a drink from the database I want to display the recipe with an image but I'm unable to require it by doing the following.

<img src={require(`../images/${drink.filename}`)} alt=""/>

Error: Cannot find module './'

I don't know if this is even possible or if I have to do it another way but thanks in advance :)

1 Answers1

1

if you are using create-react-app you can access files in public directory using path

change it to

<img src={`images/${drink.filename}`} alt=""/>
Zohaib Ijaz
  • 21,926
  • 7
  • 38
  • 60