{"id":15307937,"url":"https://github.com/wscats/lazy-preload","last_synced_at":"2026-02-25T21:01:31.731Z","repository":{"id":72736078,"uuid":"505084196","full_name":"Wscats/lazy-preload","owner":"Wscats","description":"Wraps the React.lazy API with preloaded functionality.","archived":false,"fork":false,"pushed_at":"2022-06-19T11:31:08.000Z","size":93,"stargazers_count":39,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-14T23:13:44.710Z","etag":null,"topics":["lazy","preload","react"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/lazy-preload","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/Wscats.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-06-19T11:00:55.000Z","updated_at":"2025-02-23T08:23:53.000Z","dependencies_parsed_at":"2024-02-15T21:52:12.239Z","dependency_job_id":null,"html_url":"https://github.com/Wscats/lazy-preload","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wscats%2Flazy-preload","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wscats%2Flazy-preload/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wscats%2Flazy-preload/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wscats%2Flazy-preload/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Wscats","download_url":"https://codeload.github.com/Wscats/lazy-preload/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248975329,"owners_count":21192210,"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","preload","react"],"created_at":"2024-10-01T08:13:00.262Z","updated_at":"2026-02-25T21:01:26.697Z","avatar_url":"https://github.com/Wscats.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"`lazy-preload` wraps the `React.lazy()` API and adds the ability to preload the component before it is rendered for the first time.\n\n## Install\n\n```sh\nnpm install lazy-preload\n```\n\n## Usage\n\n**Before:**\n\n```js\nimport {\n    lazy,\n    Suspense\n} from \"react\";\nconst LazyLoadComponent = lazy(() =\u003e import(\"./LazyLoadComponent\"));\n```\n\n**After:**\n\n```js\nimport {\n    Suspense\n} from \"react\";\nimport {\n    lazyWithPreload\n} from \"lazy-preload\";\nconst LazyLoadComponent = lazyWithPreload(() =\u003e import(\"./LazyLoadComponent\"));\n\n// ...\nLazyLoadComponent.preload();\n```\n\nTo preload a component before it is rendered for the first time, the component that is returned from `lazy()` has a `preload` function attached that you can invoke. `preload()` returns a `Promise` that you can wait on if needed. The promise is idempotent, meaning that `preload()` will return the same `Promise` instance if called multiple times.\n\nFor more information about React code-splitting, `React.lazy` and `React.Suspense` , see https://reactjs.org/docs/code-splitting.html.\n\n## Example\n\nFor example, if you need to load a component when a button is pressed, you could start preloading the component when the user hovers over the button:\n\n```tsx\nimport { lazyWithPreload, LazyLoadComponent } from 'lazy-preload';\nconst Component = lazyWithPreload(() =\u003e import(\"./component\"));\n\nexport function render() {\n  return \u003cLazyLoadComponent\n        defaultLoadComponent={\u003c\u003eIcon\u003c/\u003e}\n        loading={\u003cdiv\u003eLoading\u003c/div\u003e}\n        lazyLoadComponent={Component}\n    \u003e\n        \u003cComponent  {...options} /\u003e\n    \u003c/LazyLoadComponent\u003e\n}\n```\n\n## Acknowledgements\n\nInspired by the preload behavior of [react-loadable](https://github.com/jamiebuilds/react-loadable) and [react-lazy-with-preload](https://github.com/ianschmitz/react-lazy-with-preload).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwscats%2Flazy-preload","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwscats%2Flazy-preload","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwscats%2Flazy-preload/lists"}