I have this script to load an image
function loadImage(URL) {
var img = new Image();
img.onerror = () => alert('image not found');
img.src = URL;
}
loadImage("http://example.com/bar.jpg");
how can I retry a few times to load the image and then fail onerror?
btw. I´m using react. if there´s a way to do it with react. even better!