{"id":19850789,"url":"https://github.com/jlarky/react-lazily","last_synced_at":"2025-04-09T09:08:36.412Z","repository":{"id":57333758,"uuid":"317632002","full_name":"JLarky/react-lazily","owner":"JLarky","description":"react-lazily is a simple wrapper around React.lazy that supports named imports","archived":false,"fork":false,"pushed_at":"2023-09-15T11:05:01.000Z","size":137,"stargazers_count":97,"open_issues_count":3,"forks_count":5,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-02T02:28:50.859Z","etag":null,"topics":["react"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/react-lazily","language":"JavaScript","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/JLarky.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,"publiccode":null,"codemeta":null}},"created_at":"2020-12-01T18:28:26.000Z","updated_at":"2024-12-17T19:24:57.000Z","dependencies_parsed_at":"2024-06-18T18:25:08.708Z","dependency_job_id":"a08067bc-668d-4c38-a6aa-35b54ebf83b4","html_url":"https://github.com/JLarky/react-lazily","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"70f4dd3b279f42786f2da64567708213b4e7d1f2"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JLarky%2Freact-lazily","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JLarky%2Freact-lazily/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JLarky%2Freact-lazily/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JLarky%2Freact-lazily/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JLarky","download_url":"https://codeload.github.com/JLarky/react-lazily/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008630,"owners_count":21032556,"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":["react"],"created_at":"2024-11-12T13:27:45.821Z","updated_at":"2025-04-09T09:08:36.393Z","avatar_url":"https://github.com/JLarky.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-lazily\n\n[![minzip size](https://badgen.deno.dev/bundlephobia/minzip/react-lazily)](https://bundlephobia.com/result?p=react-lazily)\n[![install size](https://badgen.deno.dev/packagephobia/install/react-lazily)](https://packagephobia.com/result?p=react-lazily)\n[![dependency count](https://badgen.deno.dev/bundlephobia/dependency-count/react-lazily)](https://bundlephobia.com/result?p=react-lazily)\n\n`react-lazily` is a simple wrapper around `React.lazy` (or `loadable` from `@loadable/component`) that supports named imports.\n\n## Usage\n\nConsider a component `MyComponent` that is exported with a default export:\n\n```ts\nexport default MyComponent;\n```\n\nPer React docs, you could use `React.lazy` as follows:\n\n```ts\nconst MyComponent = React.lazy(() =\u003e import('./MyComponent'));\n```\n\nHowever, if the component is exported with a named export:\n\n```ts\nexport const MyComponent = ...\n```\n\nYou would have to use `React.lazy` like this:\n\n\n\nBut if the component is exported with named export `export const MyComponent = ...` then you have to do:\n\n```ts\nconst MyComponent = React.lazy(() =\u003e\n  import('./MyComponent').then((module) =\u003e ({ default: module.MyComponent }))\n);\n```\n\nWith `react-lazily` it becomes:\n\n```ts\nconst { MyComponent } = lazily(() =\u003e import('./MyComponent'));\n```\n\n## Full example\n\nSee the live example: https://codesandbox.io/s/react-lazily-example-p7hyj\n\n```ts\nimport React, { Suspense } from 'react';\nimport { lazily } from 'react-lazily';\n\nconst { MyComponent } = lazily(() =\u003e import('./MyComponent'));\n\nconst App = () =\u003e {\n  const [open, setOpen] = React.useReducer(() =\u003e true, false);\n\n  return (\n    \u003c\u003e\n      {open ? (\n        \u003cSuspense fallback={\u003cdiv\u003eLoading...\u003c/div\u003e}\u003e\n          \u003cMyComponent /\u003e\n        \u003c/Suspense\u003e\n      ) : (\n        \u003cbutton onClick={setOpen}\u003eLoad\u003c/button\u003e\n      )}\n    \u003c/\u003e\n  );\n};\n```\n\n## Full Example with @loadable/component\n\nDon't forget to install `@loadable/component` first.\n\n```ts\nimport React from 'react';\nimport { loadable } from 'react-lazily/loadable';\n\nconst { MyComponent } = loadable(() =\u003e import('./MyComponent'), {\n  fallback: \u003cdiv\u003eLoading...\u003c/div\u003e,\n});\n\nconst App = () =\u003e {\n  const [open, setOpen] = React.useReducer(() =\u003e true, false);\n\n  return (\n    \u003c\u003e\n      {open ? \u003cMyComponent /\u003e : \u003cbutton onClick={setOpen}\u003eLoad\u003c/button\u003e}\n    \u003c/\u003e\n  );\n};\n```\n\n## Related\n\n- [Allow for named imports in React.lazy (GitHub Issue)](https://github.com/facebook/react/issues/14603#issuecomment-726551598)\n- [Can you deconstruct lazily loaded React components? (Stack Overflow)](https://stackoverflow.com/a/61879800/74167)\n- [solidjs-lazily (NPM Package)](https://www.npmjs.com/package/solidjs-lazily)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlarky%2Freact-lazily","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjlarky%2Freact-lazily","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlarky%2Freact-lazily/lists"}