{"name":"react-lazy-load-image-component","version":"1.4.1-beta.0","description":" React Component to lazy load images using a HOC to track window scroll position. ","main":"build/index.js","peerDependencies":{"react":"^15.x.x || ^16.x.x","react-dom":"^15.x.x || ^16.x.x"},"dependencies":{"lodash.debounce":"^4.0.8","lodash.throttle":"^4.1.1"},"devDependencies":{"babel-cli":"^6.24.1","babel-core":"^6.26.0","babel-eslint":"^8.2.2","babel-jest":"^22.4.1","babel-loader":"^7.1.4","babel-plugin-transform-object-rest-spread":"^6.26.0","babel-preset-env":"^1.6.1","babel-preset-react":"^6.24.1","css-loader":"^0.28.10","enzyme":"^3.4.4","enzyme-adapter-react-16":"^1.2.0","eslint":"^4.18.2","eslint-loader":"^2.0.0","eslint-plugin-babel":"^4.1.2","eslint-plugin-react":"^7.11.1","husky":"^3.1.0","jest":"^23.5.0","path":"^0.12.7","prettier":"^1.19.1","react":"^16.2.0","react-dom":"^16.2.0","style-loader":"^0.20.3","webpack":"^4.17.1","webpack-cli":"^3.1.2"},"scripts":{"test":"jest","start":"webpack --watch","build":"webpack","prettier":"prettier --write \"**/*.{js,jsx,json}\"","lint":"eslint src --ext=js,jsx"},"jest":{"verbose":true,"testURL":"http://localhost/"},"repository":{"type":"git","url":"git+https://github.com/Aljullu/react-lazy-load-image-component.git"},"keywords":["react","react-component","lazyload","lazyloading","lazy-loading","lazyload-images"],"author":{"name":"Albert Juhé Lluveras","email":"contact@albertjuhe.com"},"license":"MIT","bugs":{"url":"https://github.com/Aljullu/react-lazy-load-image-component/issues"},"homepage":"https://github.com/Aljullu/react-lazy-load-image-component#readme","husky":{"hooks":{"pre-commit":"npm run prettier && npm run lint"}},"readme":"<div style=\"text-align:center;\">\n  <a href=\"https://github.com/Aljullu/react-lazy-load-image-component/\"><img src=\"https://user-images.githubusercontent.com/3616980/44358570-afc8ac00-a4b5-11e8-8f7e-1ad9b7038ce5.png\" alt=\"React Lazy Load Image Component Logo\" style=\"width:463px;\"/></a>\n</div>\n\nReact Lazy Load Image Component\n===============================\n\nReact Component to lazy load images and other components/elements. Supports IntersectionObserver and includes a HOC to track window scroll position to improve performance.\n\n\"[_An easy-to-use performant solution to lazy load images in React_](https://blog.albertjuhe.com/2018/03/22/an-easy-to-use-performant-solution-to-lazy-load-images-in-react/)\"\n\n[![Build Status](https://travis-ci.org/Aljullu/react-lazy-load-image-component.svg?branch=master)](https://travis-ci.org/Aljullu/react-lazy-load-image-component)\n[![Dependency Status](https://img.shields.io/david/Aljullu/react-lazy-load-image-component.svg)](http://david-dm.org/Aljullu/react-lazy-load-image-component)\n[![Download counter](https://img.shields.io/npm/dt/react-lazy-load-image-component.svg)](https://www.npmjs.com/package/react-lazy-load-image-component)\n[![License](https://img.shields.io/npm/l/react-lazy-load-image-component.svg)](https://www.npmjs.com/package/react-lazy-load-image-component)\n\n## [Live demo](https://www.albertjuhe.com/react-lazy-load-image-component/) ([code](https://github.com/Aljullu/react-lazy-load-image-component-demo))\n\n## Features\n\n* Includes two components (`LazyLoadImage` and `LazyLoadComponent`) and a HOC (`trackWindowScroll`) which adds scroll position tracking to any component you wish.\n* Handles scroll events, resize events and re-renders that might change the position of the components. And, of course, above-the-fold on initial render.\n* Placeholder by default with the same size of the image/component.\n* A custom placeholder component or image can be specified.\n* Built-in on-visible effects (blur, black and white and opacity transitions).\n* threshold is set to 100px by default and can be modified.\n* `beforeLoad` and `afterLoad` events.\n* `debounce` and `throttle` included by default and configurable.\n* Uses IntersectionObserver for browsers that support it.\n* Server Side Rendering (SSR) compatible.\n* [TypeScript declarations](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-lazy-load-image-component/index.d.ts) hosted on DefinitelyTyped.\n\n\n## Installation\n\n```bash\n# Yarn\n$ yarn add react-lazy-load-image-component\n\n# NPM\n$ npm i --save react-lazy-load-image-component\n```\n\n\n## `LazyLoadImage` usage\n\n```javascript\nimport React from 'react';\nimport { LazyLoadImage } from 'react-lazy-load-image-component';\n\nconst MyImage = ({ image }) => (\n  <div>\n    <LazyLoadImage\n      alt={image.alt}\n      height={image.height}\n      src={image.src} // use normal <img> attributes as props\n      width={image.width} />\n    <span>{image.caption}</span>\n  </div>\n);\n\nexport default MyImage;\n```\n\n### Props\n\n| Prop | Type | Default | Description |\n|:---|:---|:---|:---|\n| afterLoad | `Function` |  | Function called after the image has been completely loaded. |\n| beforeLoad | `Function` |  | Function called right before the placeholder is replaced with the image element. |\n| delayMethod | `String` | `throttle` | Method from lodash to use to delay the scroll/resize events. It can be `throttle` or `debounce`. |\n| delayTime | `Number` | 300 | Time in ms sent to the delayMethod. |\n| effect | `String` |  | Name of the effect to use. Please, read next section with an explanation on how to use them. |\n| placeholder | `ReactClass` | `<span>` | React element to use as a placeholder. |\n| placeholderSrc | `String` | | Image src to display while the image is not visible or loaded. |\n| threshold | `Number` | 100 | Threshold in pixels. So the image starts loading before it appears in the viewport. |\n| useIntersectionObserver | `Boolean` | true | Whether to use browser's IntersectionObserver when available. |\n| visibleByDefault | `Boolean` | false | Whether the image must be visible from the beginning. |\n| wrapperClassName | `String` |  | In some occasions (for example, when using a placeholderSrc) a wrapper span tag is rendered. This prop allows setting a class to that element. |\n| ... |  |  | Any other image attribute |\n\n\n### Using effects\n\n`LazyLoadImage` includes several effects ready to be used, they are useful to add visual candy to your application, but are completely optional in case you don't need them or want to implement you own effect.\n\nThey rely on CSS and the corresponding CSS file must be imported:\n\n```javascript\nimport React from 'react';\nimport { LazyLoadImage } from 'react-lazy-load-image-component';\nimport 'react-lazy-load-image-component/src/effects/blur.css';\n\nconst MyImage = ({ image }) => (\n  <LazyLoadImage\n    alt={image.alt}\n    effect=\"blur\"\n    src={image.src} />\n);\n```\n\nThe current available effects are:\n\n* `blur`: renders a blurred image based on `placeholderSrc` and transitions to a non-blurred one when the image specified in the src is loaded.\n\n![Screenshot of the blur effect](https://user-images.githubusercontent.com/3616980/37790728-9f95529a-2e07-11e8-8ac3-5066c065e0af.gif)\n\n* `black-and-white`: renders a black and white image based on `placeholderSrc` and transitions to a colorful image when the image specified in the src is loaded.\n\n![Screenshot of the black-and-white effect](https://user-images.githubusercontent.com/3616980/37790682-864e58d6-2e07-11e8-8984-ad5d7b056d9f.gif)\n\n* `opacity`: renders a blank space and transitions to full opacity when the image is loaded.\n\n![Screenshot of the opacity effect](https://user-images.githubusercontent.com/3616980/37790755-b48a704a-2e07-11e8-91c3-fcd43a91e7b1.gif)\n\n\n## `LazyLoadComponent` usage\n\n```javascript\nimport React from 'react';\nimport { LazyLoadComponent } from 'react-lazy-load-image-component';\nimport { ArticleContent, ArticleComments } from 'my-app';\n\nconst Article = ({ articleId }) => (\n  <div>\n    <ArticleContent id={articleId} />\n    <LazyLoadComponent>\n      <ArticleComments id={articleId} />\n    </LazyLoadComponent>\n  </div>\n);\n\nexport default Article;\n```\n\n### Props\n\n| Prop | Type | Default | Description |\n|:---|:---|:---|:---|\n| afterLoad | `Function` |  | Function called after the component has been rendered. |\n| beforeLoad | `Function` |  | Function called right before the component is rendered. |\n| delayMethod | `String` | `throttle` | Method from lodash to use to delay the scroll/resize events. It can be `throttle` or `debounce`. |\n| delayTime | `Number` | 300 | Time in ms sent to the delayMethod from lodash. |\n| placeholder | `ReactClass` | `<span>` | React element to use as a placeholder. |\n| threshold | `Number` | 100 | Threshold in pixels. So the component starts loading before it appears in the viewport. |\n| useIntersectionObserver | `Boolean` | true | Whether to use browser's IntersectionObserver when available. |\n| visibleByDefault | `Boolean` | false | Whether the component must be visible from the beginning. |\n\n\n## Using `trackWindowScroll` HOC to improve performance\n\nWhen you have many elements to lazy load in the same page, you might get poor performance because each one is listening to the scroll/resize events. In that case, it's better to wrap the deepest common parent of those components with a HOC to track those events (`trackWindowScroll`).\n\nFor example, if we have an `App` which renders a `Gallery`, we would wrap the `Gallery` component with the HOC.\n\n```javascript\nimport React from 'react';\nimport { LazyLoadImage, trackWindowScroll }\n  from 'react-lazy-load-image-component';\n\nconst Gallery = ({ images, scrollPosition }) => (\n  <div>\n    {images.map((image) =>\n      <LazyLoadImage\n        key={image.key}\n        alt={image.alt}\n        height={image.height}\n        // Make sure to pass down the scrollPosition,\n        // this will be used by the component to know\n        // whether it must track the scroll position or not\n        scrollPosition={scrollPosition}\n        src={image.src}\n        width={image.width} />\n    )}\n  </div>\n);\n// Wrap Gallery with trackWindowScroll HOC so it receives\n// a scrollPosition prop to pass down to the images\nexport default trackWindowScroll(Gallery);\n```\n\nYou must set the prop `scrollPosition` to the lazy load components. This way, they will know the scroll/resize events are tracked by a parent component and will not subscribe to them.\n\n### Props\n\n`LazyLoadImage`\n\n| Prop | Type | Default | Description |\n|:---|:---|:---|:---|\n| scrollPosition | `Object` |  | Object containing `x` and `y` with the curent window scroll position. Required. |\n| afterLoad | `Function` |  | Function called after the image has been rendered. |\n| beforeLoad | `Function` |  | Function called right before the image is rendered. |\n| placeholder | `ReactClass` | `<span>` | React element to use as a placeholder. |\n| threshold | `Number` | 100 | Threshold in pixels. So the image starts loading before it appears in the viewport. |\n| visibleByDefault | `Boolean` | false | Whether the image must be visible from the beginning. |\n| ... |  |  | Any other image attribute |\n\nComponent wrapped with `trackWindowScroll` (in the example, `Gallery`)\n\n| Prop | Type | Default | Description |\n|:---|:---|:---|:---|\n| delayMethod | `String` | `throttle` | Method from lodash to use to delay the scroll/resize events. It can be `throttle` or `debounce`. |\n| delayTime | `Number` | 300 | Time in ms sent to the delayMethod from lodash. |\n| useIntersectionObserver | `Boolean` | true | Whether to use browser's IntersectionObserver when available. |\n\nNotice you can do the same replacing `LazyLoadImage` with `LazyLoadComponent`.\n\n\n## When to use `visibleByDefault`?\n\nThe prop `visibleByDefault` makes the LazyLoadImage to behave like a normal `<img>`. Why is it useful, then?\n\nImagine you are going to lazy-load an image you have already loaded in the same page. In that case, there is no need to lazy-load it because it's already stored in the cache of the user's browser. You can directly display it.\n\nMaybe the following code snippet will make it more clear:\n\n```javascript\nimport React from 'react';\nimport { LazyLoadImage, trackWindowScroll }\n  from 'react-lazy-load-image-component';\n\nconst Gallery = ({ images, scrollPosition }) => (\n  <div>\n    // We are loading landscape.jpg here\n    <img src=\"/landscape.jpg\" alt=\"Beautiful landscape\" />\n    {images.map((image) =>\n      <LazyLoadImage\n        key={image.key}\n        alt={image.alt}\n        scrollPosition={scrollPosition}\n        src={image.src}\n        // If the image we are creating here has the same src than before,\n        // we can directly display it with no need to lazy-load.\n        visibleByDefault={image.src === '/landscape.jpg'} />\n    )}\n  </div>\n);\n\nexport default trackWindowScroll(Gallery);\n```\n\n\n## Demos\n\n![Screenshot of the react-lazy-load-image-component in use](https://user-images.githubusercontent.com/3616980/37790133-ecbe042e-2e05-11e8-940b-aee50ba8df06.gif)\n\n* [weather-app](https://github.com/Aljullu/weather-app)\n* [react-flickr-gallery](https://github.com/Aljullu/react-flickr-gallery)\n* [react-lazy-load-image-component-demo](https://github.com/Aljullu/react-lazy-load-image-component-demo)\n\n\n## Common errors\n\n### Warning: setState(...): Can only update a mounted or mounting component.\n\nThat warning might appear if there are two components using `trackWindowScroll` at the same time. Notice it's not possible to have a LazyLoadImage/LazyLoadComponent inside another LazyLoadComponent for now. Also, make sure you are passing down `scrollPosition` to all components wrapped inside `trackWindowScroll`.\n","readmeFilename":"README.md","gitHead":"8c33b20b5f3fa01f8cdb89524634b85a151402ef","_id":"react-lazy-load-image-component@1.4.1-beta.0","_nodeVersion":"12.13.1","_npmVersion":"6.13.6","dist":{"integrity":"sha512-SFYu44wAMRpN9afyoeerlSprjl3K/aokueZgTW/qbqmxkEbRLUSWubr5dM1cXEAcLxFruqGdjswzB8YI3KaPBQ==","shasum":"4b47fcda23b40412bc03f66442e419a23e5cae9d","tarball":"http://registry-npm.ywwl.com/react-lazy-load-image-component/download/react-lazy-load-image-component-1.4.1-beta.0.tgz","fileCount":27,"unpackedSize":87734,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeJ127CRA9TVsSAnZWagAARbIP/0sDX0U8SodHTorOrSWW\nVQjD+HO41PVNaMc9h376t8dd0T38kB08/ZgWLRRCyXuD7aaHHMdyRVrp38us\nAUqBo8jnfGOs7pLPqoXmbH6UfK/KxAPiB8pH4xJn8Em2XGqgkBH+j7jfs8dW\ncS7otw2PFdJAbBg/HxmuQsAcLVf8wC1D/Rr4fc5ZKRcJxhlvVDOlvS5hp23j\n7rKpJ2B9hUorLoMDvmG9A42PuLNX7mOJga4YTVTDWsdVkRrVwetjA19GFfHY\nFjWuBC79jqvN1nZdOi2anaYjBLwliouXib+hy5U2xy05IhWv+gnnZs0bISBK\nif+CI+0/It9V8ZMDul5sSaM+dJs6lfthjompJGGG7QtNmpcFq/1p0f3e/vDr\nCv0IAlpyABYsmy6IUp1ttKjchkTnpPpbGyV/QfPbWYri5RXn+8dQQKNjWkSj\n9v/dKef7JkgVvtkAycfq0GQZg6n9CAuXHhciJ+ZXA9iKRfe9kou5JKV6oTAs\nPqCguOY2/8/XmqeSHR2d5RI3Jv0/M9EdJApTzl+CocbKhFWmnjG3pAls+25K\n09onWcb8AY996blr8EFRToTC9AFVh2euOlXhfLC3Zye/9IN1HoiuZVX9S9Vv\npkOvSo2vvASiXkqXZk10KBQY1oQyi4nI6ERRSidPoB7/nVCtrssKYlTLrl19\nmK1C\r\n=QVuk\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEKhnfqVJAjdY6FVrXeX2pwlvghXZQtB0n1gjdLbRpGUAiBdOGPs6X0WKgcbIGmCQFDGVYH+cnE1LDZXKmuR/a01qg=="}],"size":19710,"noattachment":false,"key":"/react-lazy-load-image-component/-/react-lazy-load-image-component-1.4.1-beta.0.tgz"},"maintainers":[{"name":"albertjuhe","email":"contact@albertjuhe.com"}],"_npmUser":{"name":"albertjuhe","email":"contact@albertjuhe.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/react-lazy-load-image-component_1.4.1-beta.0_1579638203042_0.9444242270801213"},"_hasShrinkwrap":false,"publish_time":1579638203279,"_cnpm_publish_time":1579638203279,"dist-tags":{"beta":"1.4.1-beta.0","latest":"1.6.3"}}