Created
March 22, 2018 18:45
-
-
Save Aljullu/1429425bbbec5c49a8333670ddf01e86 to your computer and use it in GitHub Desktop.
Gallery.jsx (react-lazy-load-component example)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { LazyLoadImage, trackWindowScroll } | |
from 'react-lazy-load-image-component'; | |
const Gallery = ({ images, scrollPosition }) => ( | |
<div> | |
{images.map((image) => | |
<LazyLoadImage | |
key={image.key} | |
alt={image.alt} | |
height={image.height} | |
// Make sure to pass down the scrollPosition, this | |
// will be used by the component to know it must | |
// not subscribe to the scroll/resize events | |
scrollPosition={scrollPosition} | |
src={image.src} | |
width={image.width} /> | |
)} | |
</div> | |
); | |
// Wrap Gallery with trackWindowScroll HOC so it receives | |
// a scrollPosition prop to pass down to the images | |
export default trackWindowScroll(Gallery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment