DeedMob/react-load-image

How would this be used with `srcset`

matthew-dean opened this issue · 1 comments

Say I have:

<img srcSet={this.sources.srcSet} src={this.sources.src} alt={altText} />

And I want to wrap this in this image loader component. Considering that the browser may swap the image sources after the initial load, would the image loader still work?

@matthew-dean You can pass a srcSet prop that is passed onto the first React child. As for whether the loading works as expected, I expect it to, and couldn't find any references to it on the web. This library uses the Image web API.

srcSet support: #2

relevant code:

this.img = new Image();
this.img.onload = ::this.handleLoad;
this.img.onerror = ::this.handleError;
this.img.src = this.props.src;
this.img.srcset = this.props.srcSet || this.props.src;

But to be honest, I haven't tried it, and some browsers may react differently. It would be great if you would find out how the onload event and srcSet interact!