ethanselzer / react-image-magnify

A responsive image zoom component designed for shopping sites.
https://ethanselzer.github.io/react-image-magnify
MIT License
643 stars 160 forks source link

Fallback image on error #74

Open nboukeffa opened 4 years ago

nboukeffa commented 4 years ago

Hi!

Do you know if in the current state of the library it is possible to define a default image when the original image is on error (404). I've seen that there is an onError property in SmallImageType and LargeImageType but I'm not sure how to use it since nothing is passed in parameter of it.

Thanks for your help.

Seiphir0the commented 4 years ago

@nboukeffa

actually you can use onError method to put a fallback image like you discribed:

onError: (event) => { event.target.src = "https://res.cloudinary.com/demo/image/upload/seagull.jpg"; },

aku221b commented 9 months ago

@Seiphir0the No you can't the interface is defined as below

export interface CommonImageType {
    src: string;
    srcSet?: string | undefined;
    sizes?: string | undefined;
    onLoad?: (() => void) | undefined;
    onError?: (() => void) | undefined;
}

Hence no input is expected

aku221b commented 6 months ago

@ethanselzer can I take this issue up to resolve