Skip to content

Instantly share code, notes, and snippets.

@chriszhangusc
Last active June 30, 2017 05:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriszhangusc/3602bdb5b915e2c0fda553dde43c3243 to your computer and use it in GitHub Desktop.
Save chriszhangusc/3602bdb5b915e2c0fda553dde43c3243 to your computer and use it in GitHub Desktop.
import React from 'react';
import { getDisplayName } from 'common/utils/hocUtils';
export default function withImageFadeInOnLoad(ImageComponent) {
class FadeInImage extends React.Component {
constructor(props) {
super(props);
this.state = {
imageLoaded: false,
};
this.handleImageLoaded = this.handleImageLoaded.bind(this);
}
handleImageLoaded() {
this.setState({
imageLoaded: true,
});
}
render() {
return (
<ImageComponent
loaded={this.state.imageLoaded}
onLoad={this.handleImageLoaded}
{...this.props}
/>
);
}
}
FadeInImage.displayName = `WithImgFadeInOnLoad(${getDisplayName(ImageComponent)})`;
return FadeInImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment