Could you please tell me how to replace src
of image, while making list in react? I have one list in which there is an image and it's caption. I want to exchange src
url in my img
tag when image not present.
If image is present on server then it's fine, if not - I want to replace src
url to this one http://punemirror.indiatimes.com/photo/55813567.cms
.
Here is my code https://codesandbox.io/s/KOrGKp3B8
I have tried like this: there is function which detect whether image present or not. But how I will use this function in react?
imageExists(url, callback) {
var img = new Image();
img.onload = function () {
callback(true);
};
img.onerror = function () {
callback(false);
};
img.src = url;
}