Estou tentando acessar uma imagem estática para usar em uma backgroundImagepropriedade embutida no React. Infelizmente, fiquei sem saber como fazer isso.
Geralmente, achei que você fez o seguinte:
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>
);
}
}
Isso funciona para <img>tags. Alguém pode explicar a diferença entre os dois?
Exemplo:
<img src={ Background } /> funciona muito bem.
Obrigado!