{"id":18323789,"url":"https://github.com/saitolume/use-lazyload-ref","last_synced_at":"2025-08-08T04:42:24.344Z","repository":{"id":57388169,"uuid":"230906662","full_name":"saitolume/use-lazyload-ref","owner":"saitolume","description":"🖼️ Custom hook to use lazyload easily","archived":false,"fork":false,"pushed_at":"2020-10-13T16:44:16.000Z","size":112,"stargazers_count":58,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-30T20:33:38.417Z","etag":null,"topics":["custom-hook","lazyload","react"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/use-lazyload-ref","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/saitolume.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-30T11:49:41.000Z","updated_at":"2023-03-12T09:35:45.000Z","dependencies_parsed_at":"2022-09-05T03:10:20.380Z","dependency_job_id":null,"html_url":"https://github.com/saitolume/use-lazyload-ref","commit_stats":null,"previous_names":["saitoeku3/use-lazyload-ref"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saitolume%2Fuse-lazyload-ref","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saitolume%2Fuse-lazyload-ref/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saitolume%2Fuse-lazyload-ref/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saitolume%2Fuse-lazyload-ref/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saitolume","download_url":"https://codeload.github.com/saitolume/use-lazyload-ref/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247415783,"owners_count":20935383,"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":["custom-hook","lazyload","react"],"created_at":"2024-11-05T18:29:34.948Z","updated_at":"2025-04-05T23:31:33.299Z","avatar_url":"https://github.com/saitolume.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# use-lazyload-ref\n\n[![GitHub license](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/saitoeku3/use-lazyload-ref/blob/master/LICENSE) [![npm version](https://badge.fury.io/js/use-lazyload-ref.svg)](https://badge.fury.io/js/use-lazyload-ref) ![CI Status](https://github.com/saitoeku3/use-lazyload-ref/workflows/Node%20CI/badge.svg)\n\n\u003e Custom hook to use lazyload easily\n\n## Installation\n\n```\n$ npm install use-lazyload-ref\n$ yarn add use-lazyload-ref\n```\n\n## Usage\n\nTo enable lazy loading, simply specify `ref` and `data-src` attributes.\n\n```jsx\nimport React from 'react'\nimport useLazyloadRef from 'use-lazyload-ref'\n\nconst Component = ({ url }) =\u003e {\n  const [ref, hasLoaded] = useLazyloadRef()\n\n  return (\n    \u003cdiv\u003e\n      {hasLoaded || \u003cSkeleton /\u003e}\n      \u003cimg ref={ref} data-src={url} /\u003e\n      {/* \u003caudio ref={ref} data-src={url} /\u003e*/}\n      {/* \u003ciframe ref={ref} data-src={url} /\u003e*/}\n      {/* \u003cvideo ref={ref} data-src={url} /\u003e*/}\n      {/* \u003cdiv style={{ backgroundImage: `url(${url})` }}\u003e\u003c/div\u003e*/}\n    \u003c/div\u003e\n  )\n}\n```\n\n## API\n\n### `useLazyloadRef: () =\u003e [(node: HTMLElement | null) =\u003e void, boolean]`\n\nCustom hook.\nIn addition to `src` in `audio`, `iframe`, `img` and `video`, CSS property `background-image` can be lazy loaded.\n\n```jsx\nconst [ref, hasLoaded] = useLazyloadRef()\n```\n\n`useLazyloadRef` returns a callback ref function and a load state.\n\n- `ref`: Initialize observer for lazyload.\n- `hasLoaded`: Default is false. Turn true if the source has finished loading.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaitolume%2Fuse-lazyload-ref","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaitolume%2Fuse-lazyload-ref","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaitolume%2Fuse-lazyload-ref/lists"}