{"id":20069868,"url":"https://github.com/garthenweb/react-viewport-utils","last_synced_at":"2025-05-05T19:32:55.191Z","repository":{"id":32921905,"uuid":"146217396","full_name":"garthenweb/react-viewport-utils","owner":"garthenweb","description":"Utility components for working with the viewport in react","archived":false,"fork":false,"pushed_at":"2023-03-06T13:57:01.000Z","size":1875,"stargazers_count":18,"open_issues_count":14,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-21T21:39:48.065Z","etag":null,"topics":["component","dimensions","event","height","observer","react","resize","screen","scroll","size","viewport","width","window"],"latest_commit_sha":null,"homepage":null,"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/garthenweb.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":"2018-08-26T21:22:04.000Z","updated_at":"2023-03-11T15:11:16.000Z","dependencies_parsed_at":"2024-06-19T20:13:43.151Z","dependency_job_id":null,"html_url":"https://github.com/garthenweb/react-viewport-utils","commit_stats":{"total_commits":232,"total_committers":6,"mean_commits":"38.666666666666664","dds":0.09482758620689657,"last_synced_commit":"0d57f57f8ee6e7193f79b1db4b71a98622446907"},"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garthenweb%2Freact-viewport-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garthenweb%2Freact-viewport-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garthenweb%2Freact-viewport-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garthenweb%2Freact-viewport-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/garthenweb","download_url":"https://codeload.github.com/garthenweb/react-viewport-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252563006,"owners_count":21768384,"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":["component","dimensions","event","height","observer","react","resize","screen","scroll","size","viewport","width","window"],"created_at":"2024-11-13T14:16:25.037Z","updated_at":"2025-05-05T19:32:54.173Z","avatar_url":"https://github.com/garthenweb.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React Viewport Utils\n\nA set of low level utility components for react to make working with the viewport (e.g scroll position or size of the page) easy to use and performant by default.\n\n![](https://img.shields.io/npm/l/react-viewport-utils.svg)\n[![](https://img.shields.io/npm/v/react-viewport-utils.svg)](https://www.npmjs.com/package/react-viewport-utils)\n![](https://img.shields.io/david/garthenweb/react-viewport-utils.svg)\n[![](https://img.shields.io/bundlephobia/minzip/react-viewport-utils.svg)](https://bundlephobia.com/result?p=react-viewport-utils)\n[![Build Status](https://travis-ci.org/garthenweb/react-viewport-utils.svg?branch=master)](https://travis-ci.org/garthenweb/react-viewport-utils)\n[![Coverage Status](https://coveralls.io/repos/github/garthenweb/react-viewport-utils/badge.svg?branch=master)](https://coveralls.io/github/garthenweb/react-viewport-utils?branch=master)\n\nSee the example folder for more information about what you can build with it.\n\n## Why?\n\nOn a website with more sophisticated user interactions a lot of components need access to viewport information to e.g. know whether they are in the viewport, should resize or trigger an animation.\n\nMost of the libraries reimplement the required functionality for that kind of features on its own over and over again. Those functionalities are not just hard to implement but can also, if not done well, cause the UX to suffer by introducing [layout thrashing](https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing) and therefore [jank](http://jankfree.org/) and  will also cause the bundle size to grow which reduce the [time to interaction](https://philipwalton.com/articles/why-web-developers-need-to-care-about-interactivity/). Further its hard to prioritize between highly and less important events if the implementation is not bundled in one central position.\n\nThis library solves all those issues by\n\n* using one central event handler per event to collect data\n* triggers updates to components using request animation frame\n* allows to prioritize the importance of updates at runtime which allows to drop frames for less important updates in case the main thread is busy\n* implements patterns like `onUpdate` callbacks, [render props](https://reactjs.org/docs/render-props.html), [higher order components](https://reactjs.org/docs/higher-order-components.html) and [hooks](https://reactjs.org/docs/hooks-intro.html) which make the developer experience as simple as possible and allows the developer to concentrate on the application and not on global event handling.\n\n## Installation/ requirements\n\nPlease note that `react` version 16.3 or higher is required for this library to work because it is using the [context](https://reactjs.org/docs/context.html) as well as [references](https://reactjs.org/docs/refs-and-the-dom.html) api.\n\n```\nnpm install --save react-viewport-utils\n```\n\nBy default the library ships with Typescript definitions, so there is no need to install a separate dependency. Typescript is no a requirement, all type definition are served within separate files.\n\nFor detection of some resize events the `ResizeObserver` API is used internally which is not supported in some browsers. Please make sure to implement a polyfill on your own in case its required for your application.\n\n## Supported Environments\n\n### Browsers\n\nThe goal is to support the most recent versions of all major browsers (Edge, Safari, Chrome and Firefox).\n\nWe try to be downward compatible with older browsers when possible to at least not throw errors, but older versions will not be test at all.\n\nIn case you have specific requirements, please fill an issue or create a PR so we can discuss about them.\n\n### NodeJS\n\nThe project aims to support recent releases of v8 and v10 and higher of NodeJS.\n\n## Documentation\n\n### API\n\n* [`ViewportProvider`](docs/api/ViewportProvider.md)\n* [`ObserveViewport`](docs/api/ObserveViewport_connectViewport_useViewport.md#render-props-event-handler-observeviewport)\n* [`connectViewport`](docs/api/ObserveViewport_connectViewport_useViewport.md#hoc-connectviewport)\n* [`useViewport`](docs/api/ObserveViewport_connectViewport_useViewport.md#hooks-useviewport-usescroll-usedimensions-useLayoutSnapshot)\n* [`useMutableViewport`](https://github.com/garthenweb/react-viewport-utils/blob/master/docs/api/ObserveViewport_connectViewport_useViewport.md#hooks-usemutableviewport)\n* [`useScroll`](docs/api/ObserveViewport_connectViewport_useViewport.md#hooks-useviewport-usescroll-usedimensions-useLayoutSnapshot)\n* [`useDimensions`](docs/api/ObserveViewport_connectViewport_useViewport.md#hooks-useviewport-usescroll-usedimensions-useLayoutSnapshot)\n* [`useLayoutSnapshot`](docs/api/ObserveViewport_connectViewport_useViewport.md#hooks-useviewport-usescroll-usedimensions-useLayoutSnapshot)\n* [`useViewportEffect`](docs/api/ObserveViewport_connectViewport_useViewport.md#hook-effects-useViewportEffect-useScrollEffect-useDimensionsEffect)\n* [`useScrollEffect`](docs/api/ObserveViewport_connectViewport_useViewport.md#hook-effects-useViewportEffect-useScrollEffect-useDimensionsEffect)\n* [`useDimensionsEffect`](docs/api/ObserveViewport_connectViewport_useViewport.md#hook-effects-useViewportEffect-useScrollEffect-useDimensionsEffect)\n* [`useRect`](docs/api/useRect.md#useRect)\n* [`useRectEffect`](docs/api/useRect.md#useRectEffect)\n* [Types](docs/api/types.md)\n\n### Concepts\n\n* [Experimental Scheduler](docs/concepts/scheduler.md)\n* [recalculateLayoutBeforeUpdate](docs/concepts/recalculateLayoutBeforeUpdate.md)\n* [Defer Events](docs/concepts/defer_events.md)\n\n## License\n\nLicensed under the [MIT License](https://opensource.org/licenses/mit-license.php).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarthenweb%2Freact-viewport-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgarthenweb%2Freact-viewport-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarthenweb%2Freact-viewport-utils/lists"}