I have a react component that is the detail view from a list.
I am trying to replace the image with a default image if the image does not exist and there is a 404 er
If anyone is using image src with require then onError doesn't work as -
then require throws an error, where I tried multiple ways and came to try and catch block solution as -
let imgSrc;
try {
imgSrc = require(`./../../assets/images/${props.imgName}.png`);
} catch {
imgSrc = require(`./../../assets/images/default.png`);
}
and use as