I am setting my background image on CDM but document.body.style={mainBg}
does not set the background image as I expected and the console statement below it prints out an empty string. Can anyone help me figure out what I am doing wrong?
const mainBg = {
backgroundImage: 'url("../img/background.jpg")',
backgroundPosition: 'center',
backgroundRepeat: 'no-repeat',
backgroundAttachment: 'fixed',
backgroundSize: 'cover',
};
class Home extends Component {
componentDidMount() {
console.log(mainBg);
document.body.style = {mainBg};
console.log(document.body.style.backgroundImage)
}
}
EDIT: I am looking to set the background image for the body.