Looking to incorporate a background image from an API response in ReactJS
Here is some 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>
Attempting to store the retrieved image in a variable, everything seems to be functioning properly but the image (received in the response) is not displaying as a background.