Setting a backgroundImage With React Inline Styles
I'm trying to access a static image to use within an inline backgroundImage
property within React. Unfortunately, I've run up dry on how to do this.
Generally, I thought you just did as follows:
import Background from '../images/background_image.png';
var sectionStyle = {
width: "100%",
height: "400px",
backgroundImage: "url(" + { Background } + ")"
};
class Section extends Component {
render() {
return (
<section style={ sectionStyle }>
</section>
);
}
}
This works for <img>
tags. Can someone explain the difference between the two?
Example:
<img src={ Background } />
works just fine.
Thank you!