{"id":17364673,"url":"https://github.com/tejasq/react-hook-intersection-observer","last_synced_at":"2025-04-15T01:44:17.599Z","repository":{"id":82379576,"uuid":"158357563","full_name":"TejasQ/react-hook-intersection-observer","owner":"TejasQ","description":"A simple React hook that works with the Intersection Observer API.","archived":false,"fork":false,"pushed_at":"2019-02-23T16:54:11.000Z","size":7,"stargazers_count":33,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-16T23:59:24.636Z","etag":null,"topics":["hooks","intersectionobserver","react","web"],"latest_commit_sha":null,"homepage":"https://codesandbox.io/s/r45lrl8rzm","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/TejasQ.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-11-20T08:43:25.000Z","updated_at":"2021-10-12T18:39:11.000Z","dependencies_parsed_at":"2023-03-02T08:15:55.225Z","dependency_job_id":null,"html_url":"https://github.com/TejasQ/react-hook-intersection-observer","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/TejasQ%2Freact-hook-intersection-observer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TejasQ%2Freact-hook-intersection-observer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TejasQ%2Freact-hook-intersection-observer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TejasQ%2Freact-hook-intersection-observer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TejasQ","download_url":"https://codeload.github.com/TejasQ/react-hook-intersection-observer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248792291,"owners_count":21162344,"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":["hooks","intersectionobserver","react","web"],"created_at":"2024-10-15T20:43:19.932Z","updated_at":"2025-04-15T01:44:17.577Z","avatar_url":"https://github.com/TejasQ.png","language":"JavaScript","readme":"# `useIntersectionObserver`\nThis simple [React](https://reactjs.org/) [Hook](https://reactjs.org/docs/hooks-intro.html) uses the [Intersection Observer](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) API in order to relay information to your UI about whether a given element is **intersecting** with the viewport.\n\n## Getting Started\n\nFirstly, you'll want to `yarn add react-hook-intersection-observer` into your project.\n\nThen, using this is as simple as:\n\n[![Edit react-hook-intersection-observer](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/r45lrl8rzm)\n\n```jsx\nimport React, { useRef, useState } from \"react\";\nimport { useIntersectionObserver } from \"react-hook-intersection-observer\";\n\nconst App = () =\u003e {\n  const root = useRef();    // We need a ref to our \"root\" or our parent,\n  const target = useRef();  // We need a ref to our \"target\" or our child-to-watch,\n\n  // Let's use a bit of state.\n  const [isThingIntersecting, setThingIntersecting] = useState(false);\n\n  // Here's our hook! Let's give it some configuration...\n  useIntersectionObserver({\n    root,\n    target,\n\n    // What do we do when it intersects?\n    // The signature of this callback is (collectionOfIntersections, observerElement).\n    onIntersect: ([{ isIntersecting }]) =\u003e setThingIntersecting(isIntersecting)\n  });\n\n  return (\n    \u003cdiv className=\"App\"\u003e\n      \u003ch1\u003euseIntersectionObserver\u003c/h1\u003e\n      \u003ch2\u003e\n        The thing is currently{\" \"}\n\n        {!isThingIntersecting \u0026\u0026 \u003cspan style={{ color: \"red\" }}\u003enot\u003c/span\u003e}{\" \"}\n\n        \u003cspan style={{ color: isThingIntersecting ? \"green\" : \"black\" }}\u003e\n          intersecting\n        \u003c/span\u003e\n\n        !\n      \u003c/h2\u003e\n\n\n      \u003cdiv ref={root} className=\"black-box\"\u003e\n        \u003cdiv className=\"larger-box\"\u003e\n          \u003cdiv ref={target}\u003eTHE THING\u003c/div\u003e\n        \u003c/div\u003e\n      \u003c/div\u003e\n    \u003c/div\u003e\n  );\n};\n```\n\n## Contributing\n\nThis project is _totally_ open for contributions. Get started by looking at the list of [open issues](https://github.com/tejasq/react-hook-intersection-observer/issues), or by opening one and we can talk about improvements! Wooo!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftejasq%2Freact-hook-intersection-observer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftejasq%2Freact-hook-intersection-observer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftejasq%2Freact-hook-intersection-observer/lists"}