Skip to content

Instantly share code, notes, and snippets.

@nikilarigela
Created September 18, 2019 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikilarigela/78cfa88e445bcfaa4f45d62e359b416d to your computer and use it in GitHub Desktop.
Save nikilarigela/78cfa88e445bcfaa4f45d62e359b416d to your computer and use it in GitHub Desktop.
class AsyncImage extends Component {
constructor(props) {
super(props);
this.state = { loaded: false };
}
onLoad = () => {
this.setState(() => ({ loaded: true }));
};
render() {
const { source, placeholder, style, ...rest } = this.props;
const { loaded } = this.state;
return (
<>
<Image
source={source}
style={loaded ? style : {}}
{...rest}
onLoad={this.onLoad}
/>
{!loaded && placeholder}
</>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment