When trying to set my background image on CDM using document.body.style={mainBg}
, I am not getting the expected result. Additionally, the console statement below it is printing out an empty string. Can anyone assist me in identifying what mistake I might be making?
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)
}
}
UPDATE: My goal is to set the background image for the body element.