How to add dynamic image in React

Posted on: February 2nd, 2022
By: Tadeo Martinez

I found this stack overflow answer:

And here’s how I applied it on my code:

var bgImg = {backgroundImage:’url(‘ + props.img + ‘)’,backgroundAttachment:”fixed”,backgroundSize:”cover”}

Note: the code below goes inside return(<>

<section className=’hero position-relative pt-2 pb-5 bg-attachment’ style={bgImg}>

Have any questions or comments? Write them below!

Leave a Reply

Your email address will not be published. Required fields are marked *