Need to set a background image from API response in ReactJS
Sample code:
useEffect(() => {
axios.get(`https://apiaddress=${API_KEY}`)
.then(res=>{
console.log(res);
setRetrieved(res.data);
console.log(retrieved);
})
.catch(err=>{
console.log(err)
})
return(
<div ClassName="home" style={{backgroundImage:`url({retrieved.imageurl}{/*or
any other var of type string*/}), width: 1920, height: 1080 } </div>
Also tried to save the retrieved image in a variable, working fine but the image (which is coming in response) is not rendered as background.