How to add dynamic image in React

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

I found this stack overflow answer: https://stackoverflow.com/questions/27966468/reactjs-change-background-image-dynamically/27967387

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 *