{"id":18396322,"url":"https://github.com/realdennis/img-suspense","last_synced_at":"2026-04-16T11:02:34.383Z","repository":{"id":44153650,"uuid":"177350188","full_name":"realdennis/img-suspense","owner":"realdennis","description":"A React.Suspense style lazy load img component! (What's new? You can use ErrorBoundary!)","archived":false,"fork":false,"pushed_at":"2022-12-08T18:55:39.000Z","size":1626,"stargazers_count":1,"open_issues_count":12,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-09T06:33:08.254Z","etag":null,"topics":["component","fallback","placeholder","react","suspense"],"latest_commit_sha":null,"homepage":"","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/realdennis.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-03-23T23:23:10.000Z","updated_at":"2022-01-20T04:59:09.000Z","dependencies_parsed_at":"2023-01-25T15:31:44.597Z","dependency_job_id":null,"html_url":"https://github.com/realdennis/img-suspense","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/realdennis/img-suspense","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realdennis%2Fimg-suspense","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realdennis%2Fimg-suspense/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realdennis%2Fimg-suspense/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realdennis%2Fimg-suspense/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/realdennis","download_url":"https://codeload.github.com/realdennis/img-suspense/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realdennis%2Fimg-suspense/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31882886,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T09:23:21.276Z","status":"ssl_error","status_checked_at":"2026-04-16T09:23:15.028Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["component","fallback","placeholder","react","suspense"],"created_at":"2024-11-06T02:13:25.412Z","updated_at":"2026-04-16T11:02:34.342Z","avatar_url":"https://github.com/realdennis.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# img-suspense\n\n[![Build Status](https://travis-ci.org/realdennis/img-suspense.svg?branch=master)](https://travis-ci.org/realdennis/img-suspense)\n[![Coverage Status](https://coveralls.io/repos/github/realdennis/img-suspense/badge.svg?branch=master)](https://coveralls.io/github/realdennis/img-suspense?branch=master)\n\n![Gif Demo](https://media.giphy.com/media/3ZYutsrBnh8DmoLN27/giphy.gif)\n\n[Demo](https://codesandbox.io/s/k3jx7l96po)\n\nA React img component like **React.Suspense**!\n\nActually, its all props are same as `\u003cimg/\u003e` like `src` `alt`...\n\n**You should pass a react element to `fallback` prop.**\n\nWhen image are still pending, it'll show fallback element.\n\n## Intallation\n\n```sh\n$ yarn add img-suspense\n```\n\n## Usage\n\n```jsx\nimport ImgSuspense from 'img-suspense';\n\n\u003cImgSuspense\n  src=\"./cutecat.jpg\"\n  alt=\"cat\"\n  style={{width:200px}}\n  fallback={\u003cp\u003ePending...\u003c/p\u003e}\n  /\u003e\n\n```\n\n## Handle Exception\n\n![Gif Demo](https://media.giphy.com/media/8F3dZPrSBmOC5OILum/giphy.gif)\n\n**Error Boundary** vs **onError**\n\nThere's an [example](https://codesandbox.io/s/3812yrjzz5) show how to handle exception.\n\n### Error Boundary\n\n```jsx\n\u003cErrorBoundary\u003e\n  \u003cImgSuspense\n    src=\"./path/picuture.jpg\"\n    alt=\"picture\"\n    fallback={\u003cp\u003ePending...\u003c/p\u003e}\n  /\u003e\n\u003c/ErrorBoundary\u003e\n```\n\nIf the **img** fails to load (for example, due to network failure), it will trigger an error.\n\nYou can handle these errors to show a nice user experience and manage recovery with Error Boundaries.\n\nThat's a same way you handle React.suspense exception.\n\n- https://reactjs.org/docs/code-splitting.html#error-boundaries\n- https://reactjs.org/docs/error-boundaries.html\n\n### Use onError to catch\n\n```jsx\n\u003cImgSuspense\n  onError={e =\u003e console.log('Error occurs! Override ImgSuspense exception')}\n  src=\"./path/picuture.jpg\"\n  alt=\"picture\"\n  fallback={\u003cp\u003ePending...\u003c/p\u003e}\n/\u003e\n```\n\nYou can just **override onError handler** to prevent component exception, treat it like an img element!\n\n---\n\nLICENSE MIT © 2019 realdennis\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealdennis%2Fimg-suspense","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frealdennis%2Fimg-suspense","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealdennis%2Fimg-suspense/lists"}