react dynamic background image code example
Example 1: how to add background image in react css
import React from 'react';
import car from './images/car.png'
function App() {
return (
<div styles={{ backgroundImage:`url(${car})` }}> <h1>This is red car</h1>
</div>
);
}
export default App;
Example 2: react background image
style={{
backgroundImage: "url(" + "https://images.pexels.com/photos/34153/pexels-photo.jpg?auto=compress&cs=tinysrgb&h=350" + ")",
backgroundPosition: 'center',
backgroundSize: 'cover',
backgroundRepeat: 'no-repeat'
}}
Example 3: how to change background image dynamically in react
render: function() {
var divImage = {
backgroundImage : "url(" + this.state.song.imgSrc + "),url(" + this.state.nextImgSrc + ");"
};
return (
<li>
<div ref="image-pane" className="player" style={divImage}></div>
</li>
)
}