JSFiddle - React, Tailwind, and code Playground
by Rodwyn Moreno
JavaScript
const imgURL = 'https://www.workylab.com/img/team/rodwyn.jpg';
getImage = async (url) => {
let response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
} else {
let myBlob = await response.blob();
let objectURL = URL.createObjectURL(myBlob);
let image = document.createElement('img');
image.src = objectURL;
return image;
//document.body.appendChild(image);
}
};
/*let myImage = getImage(imgURL).then(
img => img
).catch(error => {
console.log(
'There has been a problem with your fetch operation: ' + error.message
);
});*/
let myImage = Promise.resolve(getImage(imgURL));
console.log(myImage);