I am facing a perplexing issue that I just can't seem to resolve.
const handleImageError = e => {
e.target.onerror = null;
e.target.src = 'factory2.svg';
e.target.width = 45;
e.target.height = 41;
};
items.map(item => {
if(item.data) {
<img src={`${item.data}?size=20`} onError={handleImageError} />
} else {
<Logo styleName="defaultIconLogo" width={25} height={20} />
}
})
In dealing with image errors, the function above switches an image to another source ('factory.svg') and adjusts its dimensions in case of an error. The problem arises when an image successfully loads with pre-set dimensions from the incoming source but then gets overridden by the errorHandler, resulting in new width='45'
and height='41'
. These dimensions should only be applied when the source URL fails to load.
The example source is .