I am using React with Webpack.
I have a React component that takes a prop, which is a URL and displays an image.
Since React will not know the URL of the image until runtime, can webpack "require" the URL of the image?
import React, {Component} from 'react' export default class Episode extends Component { constructor(props){ super(props) } render(){ let imageStyle = {backgroundImage: 'url(' + this.props.episode.url +')'} return ( <div className="episode"> <div className="image" style={imageStyle}> <h2>{this.props.episode.category}</h2> </div> <h3>Episode {this.props.episode.number}</h3> </div> ) } }
For reference, my images are in:
src/assets/images
and my web package is built on dist
source share