{"id":13473141,"url":"https://github.com/imbhargav5/react-lazy-progressive-image","last_synced_at":"2025-03-26T17:32:10.001Z","repository":{"id":56152567,"uuid":"117643548","full_name":"imbhargav5/react-lazy-progressive-image","owner":"imbhargav5","description":"React Progressive images with Lazy loading :zap:","archived":true,"fork":false,"pushed_at":"2020-11-23T23:40:21.000Z","size":16985,"stargazers_count":44,"open_issues_count":15,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T16:19:40.952Z","etag":null,"topics":["lazy-load-img","progressive-image","reactjs"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/react-lazy-progressive-image","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imbhargav5.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-16T06:49:36.000Z","updated_at":"2025-02-11T15:50:06.000Z","dependencies_parsed_at":"2022-08-15T13:40:43.595Z","dependency_job_id":null,"html_url":"https://github.com/imbhargav5/react-lazy-progressive-image","commit_stats":null,"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imbhargav5%2Freact-lazy-progressive-image","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imbhargav5%2Freact-lazy-progressive-image/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imbhargav5%2Freact-lazy-progressive-image/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imbhargav5%2Freact-lazy-progressive-image/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imbhargav5","download_url":"https://codeload.github.com/imbhargav5/react-lazy-progressive-image/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245702451,"owners_count":20658619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lazy-load-img","progressive-image","reactjs"],"created_at":"2024-07-31T16:01:01.142Z","updated_at":"2025-03-26T17:32:08.107Z","avatar_url":"https://github.com/imbhargav5.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"![](https://github.com/imbhargav5/react-lazy-progressive-image/blob/master/.github/Logo.png?raw=true)\n\n# react-lazy-progressive-image\n\nLoad low resolution/ placeholder image first and then load the actual image lazily when it's in the viewport.\n\n\u003chr/\u003e\n\n[![](https://nodei.co/npm/react-lazy-progressive-image.png?compact=true)](https://nodei.co/npm/react-lazy-progressive-image/)\n\n[![npm](https://img.shields.io/npm/dm/react-lazy-progressive-image.svg?style=for-the-badge)](https://www.npmjs.com/package/react-lazy-progressive-image)\n[![npm](https://img.shields.io/npm/l/react-lazy-progressive-image.svg?style=for-the-badge)](https://www.npmjs.com/package/react-lazy-progressive-image)\n![Build Status](https://github.com/imbhargav5/react-lazy-progressive-image/workflows/Tests/badge.svg)\n\n\u003c/p\u003e\n\u003chr/\u003e\n\n\u003cimg src=\"https://github.com/imbhargav5/react-lazy-progressive-image/blob/master/.github/screenshare.gif?raw=true\"/\u003e\n\n\u003chr/\u003e\n\n# :zap: Why?\n\nLoad low resolution/ placeholder image first and then load the actual image lazily when it's in the viewport.\n\n\u003chr/\u003e\n\n# :zap: Installation\n\nThe package is available on npm.\n\n```bash\nnpm i -s react-lazy-progressive-image\n```\n\n\u003chr/\u003e\n\n# :zap: Usage\n\nJust like `react-progressive-image` this component expects exactly one child which has to be a function.\n\n```javascript\nimport React, { Component } from \"react\";\nimport LazyImage from \"react-lazy-progressive-image\";\n\nclass App extends Component {\n  render() {\n    return (\n      \u003cLazyImage\n        placeholder={\"http://example.com/placeholder.png\"}\n        src={\"http://example.com/src.png\"}\n      \u003e\n        {(src, loading, isVisible) =\u003e \u003cimg src={src} /\u003e}\n      \u003c/LazyImage\u003e\n    );\n  }\n}\n```\n\nThe child which is a function will have access to `src`, `loading` and `isVisible` values as arguments and the user can decide how to use those values to render image styles. (This pattern is called render props or children props pattern)\n\n| Render prop           | Description                                                                                      | Type    | Values                                                                                              |\n| --------------------- | ------------------------------------------------------------------------------------------------ | ------- | --------------------------------------------------------------------------------------------------- |\n| src                   | The src of the image being rendered                                                              | String  | Initially points to the placeholder image, then loads image and will then point to the source image |\n| loading               | Whether the image is currently being loaded                                                      | Boolean | true/false                                                                                          |\n| isVisible             | Whether the image is currently visible in the page. This is managed by `react-visibility-sensor` | Boolean | true/false                                                                                          |\n| visibilitySensorProps | Props to pass to `react-visibility-sensor` . Handy for `partialVisibility`                       | Object  | `undefined` or `{}`                                                                                 |\n\n\u003chr/\u003e\n\n### Example usage with styled-components\n\nYou can use `styled-components`, to transition an image from the placeholder when the image has loaded.\nYou can use the `render props` as mentioned above and then use it to animate the `opacity` of the image from `0.2` to `1` when the image is loaded. This is , of course, a basic example. But you can use this logic to create more powerful animations.\n\nFor eg :\n\n```javascript\nimport React, { Component } from \"react\";\nimport styled from \"styled-components\";\nimport LazyImage from \"react-lazy-progressive-image\";\n\nconst Image = styled.img`\n  height: 450px;\n  width: 800px;\n  margin-top: 200px;\n  display: block;\n  transition: all 0.25s ease;\n  opacity: ${props =\u003e (props.loading ? 0.2 : 1)};\n`;\n\nclass Usage extends Component {\n  render() {\n    return (\n      \u003cLazyImage\n        src={\"/assets/imageURL\"}\n        placeholder={\"/assets/placeholderURL\"}\n      \u003e\n        {(src, loading) =\u003e \u003cImage src={src} loading={loading} /\u003e}\n      \u003c/LazyImage\u003e\n    );\n  }\n}\n```\n\n\u003chr/\u003e\n\n## How was this package made 🔧\n\nA good amount of code has been taken from \u003ca href=\"https://github.com/FormidableLabs/react-progressive-image\"\u003ereact-progressive-image\u003c/a\u003e, the additions being the usage of \u003ca href=\"https://github.com/joshwnj/react-visibility-sensor\"\u003ereact-visibility-sensor\u003c/a\u003e to check if there is a need to load the image and making sure that the image doesn't load in advance when it's not really needed.\n\n\u003chr/\u003e\n\n### ✊ Improvements in the roadmap\n\n- [x] Unit tests\n- [x] Integration tests\n- [ ] Suspense integration\n- [ ] More tests\n\n\u003chr/\u003e\n\n## 🙏 Credits\n\n1. \u003ca href=\"https://github.com/FormidableLabs\"\u003e Formidable Labs \u003c/a\u003e\n2. \u003ca href=\"https://github.com/joshwnj\"\u003e Josh Johnston \u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimbhargav5%2Freact-lazy-progressive-image","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimbhargav5%2Freact-lazy-progressive-image","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimbhargav5%2Freact-lazy-progressive-image/lists"}