Skip to content

Instantly share code, notes, and snippets.

@andrisgauracs
Last active December 30, 2018 22:00
Show Gist options
  • Select an option

  • Save andrisgauracs/d1d1c5bffadc7728535a80d10ff01389 to your computer and use it in GitHub Desktop.

Select an option

Save andrisgauracs/d1d1c5bffadc7728535a80d10ff01389 to your computer and use it in GitHub Desktop.
An image wrapper component, that holds all of our data inside it, plus it get triggered to run only when scrolled into view
/* an image wrapper component, that holds
all of our data inside it, plus it
get triggered to run only when scrolled into view. */
const ImageWrapper = ({ image, nr, render }) => (
render ?
<ImageContainer>
<Suspense fallback={
<ImageContainer> {/* This gets shown while the full res image is preloading */}
<img className="blurry" src={image.small} alt={`img_small_${nr}`}/>
{/* This gets shown below while the low res image is preloading */}
<Style.Loader>{'Loading...'}</Style.Loader>
</ImageContainer>
}>
<ImageContainer>
{/* This gets shown when the full res image is finally loaded */}
<Img src={image.large} alt={`img_large_${nr}`}/>
</ImageContainer>
</Suspense>
</ImageContainer>
:
<ImageContainer/>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment