Skip to content

Can't import image from src #585

Closed
Closed
@iRoachie

Description

@iRoachie

So I have a list of reviews each with an logo field which is a path to the image. The images are in an images folder in my src folder.

Example
logo: 'src/images/logos/zoosk-logo.png',

I have a Reviews component which renders out Review components from the list passing the review object as a prop.

In the Review component I then display the logo in an image tag. Like so:

<img className="review__logo" src={this.props.review.logo} alt=""/>

This works great with npm start, but when I use the run build, the images aren't copied over to the build file so the links don't work. I know if you import the image then webpack will bundle it in the build step. But I can't import it, because the path comes from a prop, and imports can only be done at the top.

Is there anyway to go around this? I'm relatively new to react.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions