VanC
VanC

Reputation: 11

inject a react component as background-image

I am looking for the best way to inject a dynamically built image as my background image. I can build the image and I can display it as a div but I want it as the background of my body.

    <div className="App">
    <mycomonent />
    </div>

works but it is not what I want

     <body styles="background-image: {mycomponent}"></body>

Upvotes: 1

Views: 49

Answers (1)

dance2die
dance2die

Reputation: 36985

You can change using regular DOM object within React.

document.body.style.backgroundImage = `url("https://www.placecage.com/c/460/300")`;

Working Demo Edit n7mnw40xml

Upvotes: 1

Related Questions