{"id":27765023,"url":"https://github.com/bettertyped/react-window-hooks","last_synced_at":"2025-06-11T06:03:30.210Z","repository":{"id":61493613,"uuid":"519341064","full_name":"BetterTyped/react-window-hooks","owner":"BetterTyped","description":"⚙️ Set of hooks that allow handling lifecycle window and document events, window size, window scroll position and window focus state.","archived":false,"fork":false,"pushed_at":"2022-12-29T12:22:14.000Z","size":520,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-29T15:39:42.378Z","etag":null,"topics":["blur","document-events","events","focus","lifecycle","react","react-hooks","scroll","typescript","window","window-events","window-scroll","window-size"],"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/BetterTyped.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"Contributing.md","funding":null,"license":"LICENSE","code_of_conduct":"Code_of_Conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null}},"created_at":"2022-07-29T20:25:03.000Z","updated_at":"2024-03-19T01:43:52.000Z","dependencies_parsed_at":"2023-01-31T08:46:14.539Z","dependency_job_id":null,"html_url":"https://github.com/BetterTyped/react-window-hooks","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BetterTyped%2Freact-window-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BetterTyped%2Freact-window-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BetterTyped%2Freact-window-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BetterTyped%2Freact-window-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BetterTyped","download_url":"https://codeload.github.com/BetterTyped/react-window-hooks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251530441,"owners_count":21604122,"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":["blur","document-events","events","focus","lifecycle","react","react-hooks","scroll","typescript","window","window-events","window-scroll","window-size"],"created_at":"2025-04-29T15:39:49.547Z","updated_at":"2025-04-29T15:39:50.376Z","avatar_url":"https://github.com/BetterTyped.png","language":"TypeScript","readme":"# ⚙️ React Window hooks\n\n\u003cp\u003e\n  \u003ca href=\"https://bettertyped.com/\"\u003e\n    \u003cimg src=\"https://custom-icon-badges.demolab.com/static/v1?label=\u0026message=BetterTyped\u0026color=333\u0026logo=BT\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/BetterTyped/react-window-hooks\"\u003e\n    \u003cimg src=\"https://custom-icon-badges.demolab.com/github/stars/BetterTyped/react-window-hooks?logo=star\u0026color=118ab2\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/BetterTyped/react-window-hooks/blob/main/License.md\"\u003e\n    \u003cimg src=\"https://custom-icon-badges.demolab.com/github/license/BetterTyped/react-window-hooks?logo=law\u0026color=yellow\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/semantic-release/semantic-release\"\u003e\n    \u003cimg src=\"https://custom-icon-badges.demolab.com/badge/semver-commitzen-e10079?logo=semantic-release\u0026color=e76f51\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/BetterTyped/react-window-hooks\"\u003e\n    \u003cimg src=\"https://custom-icon-badges.demolab.com/badge/typescript-%23007ACC.svg?logo=typescript\u0026logoColor=white\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@better-hooks/window\"\u003e\n    \u003cimg src=\"https://custom-icon-badges.demolab.com/npm/v/@better-hooks/window.svg?logo=npm\u0026color=E10098\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@better-hooks/window\"\u003e\n    \u003cimg src=\"https://custom-icon-badges.demolab.com/bundlephobia/minzip/@better-hooks/window?color=blueviolet\u0026logo=package\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@better-hooks/window\"\u003e\n    \u003cimg src=\"https://custom-icon-badges.demolab.com/npm/dm/@better-hooks/window?logoColor=fff\u0026logo=trending-up\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## About\n\nHandle window events and observe window size\n\n## Key Features\n\n🔮 **Simple usage**\n\n🚀 **Fast and light**\n\n✨ **Lifecycle Window events**\n\n💎 **Lifecycle Document events**\n\n🎯 **Window size**\n\n🪄 **Window scroll position**\n\n💡 **Window focus**\n\n🎊 **SSR Support**\n\n## Installation\n\n```bash\nnpm install --save @better-hooks/window\n```\n\nor\n\n```bash\nyarn add @better-hooks/window\n```\n\n---\n\n## Examples\n\n#### useWindowEvent\n\n```tsx\nimport React from \"react\";\nimport { useWindowEvent } from \"@better-hooks/window\";\n\nconst MyComponent: React.FC = () =\u003e {\n  // Unmounts event with component lifecycle\n  useWindowEvent(\"scroll\", () =\u003e {\n    // ... Do something\n  });\n\n  useWindowEvent(\"wheel\", () =\u003e {\n    // ... Do something\n  });\n\n  useWindowEvent(\"resize\", () =\u003e {\n    // ... Do something\n  });\n\n  return (\n    // ...\n  )\n}\n\n```\n\n---\n\n#### useDocumentEvent\n\n```tsx\nimport React from \"react\";\nimport { useDocumentEvent } from \"@better-hooks/window\";\n\nconst MyComponent: React.FC = () =\u003e {\n  // Unmounts event with component lifecycle\n  useDocumentEvent(\"visibilitychange\", () =\u003e {\n    // ... Do something\n  });\n\n  useDocumentEvent(\"scroll\", () =\u003e {\n    // ... Do something\n  });\n\n  return (\n    // ...\n  )\n}\n\n```\n\n---\n\n#### useWindowSize\n\n```tsx\nimport React from \"react\";\nimport { useWindowSize } from \"@better-hooks/window\";\n\nconst MyComponent: React.FC = () =\u003e {\n  // Updates with resizing\n  const [width, height] = useWindowSize()\n\n  return (\n    // ...\n  )\n}\n\n```\n\n---\n\n#### useWindowScroll\n\n```tsx\nimport React from \"react\";\nimport { useWindowScroll } from \"@better-hooks/window\";\n\nconst MyComponent: React.FC = () =\u003e {\n  // Updates when scrolling\n  const [x, y] = useWindowScroll()\n\n  return (\n    // ...\n  )\n}\n\n```\n\n---\n\n#### useWindowFocus\n\n```tsx\nimport React from \"react\";\nimport { useWindowFocus } from \"@better-hooks/window\";\n\nconst MyComponent: React.FC = () =\u003e {\n  // Updates when user leave our page\n  const focus = useWindowFocus()\n\n  useEffect(() =\u003e {\n    if(focus) {\n      // User is using our page\n    } else {\n      // User has minimized window or leaved our page to different tab\n    }\n  }, [focus])\n\n  return (\n    // ...\n  )\n}\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbettertyped%2Freact-window-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbettertyped%2Freact-window-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbettertyped%2Freact-window-hooks/lists"}