{"id":16182257,"url":"https://github.com/avraammavridis/react-intersection-visible-hook","last_synced_at":"2025-03-19T02:30:37.505Z","repository":{"id":65474376,"uuid":"154786731","full_name":"AvraamMavridis/react-intersection-visible-hook","owner":"AvraamMavridis","description":"React Hook to track the visibility of a functional component","archived":false,"fork":false,"pushed_at":"2018-10-30T08:16:40.000Z","size":2999,"stargazers_count":49,"open_issues_count":2,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-27T07:32:32.351Z","etag":null,"topics":["hook","intersectionobserver","react","visibility"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AvraamMavridis.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-26T06:21:12.000Z","updated_at":"2023-03-05T06:44:48.000Z","dependencies_parsed_at":"2023-01-25T12:45:53.563Z","dependency_job_id":null,"html_url":"https://github.com/AvraamMavridis/react-intersection-visible-hook","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AvraamMavridis%2Freact-intersection-visible-hook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AvraamMavridis%2Freact-intersection-visible-hook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AvraamMavridis%2Freact-intersection-visible-hook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AvraamMavridis%2Freact-intersection-visible-hook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AvraamMavridis","download_url":"https://codeload.github.com/AvraamMavridis/react-intersection-visible-hook/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221720265,"owners_count":16869450,"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":["hook","intersectionobserver","react","visibility"],"created_at":"2024-10-10T06:29:56.446Z","updated_at":"2024-10-27T19:00:10.444Z","avatar_url":"https://github.com/AvraamMavridis.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-intersection-visible-hook\n\nReact hook to track the visibility of a functional component based on IntersectionVisible Observer.\n\nIn the following example we changed the background color of the body depending on the visibility of the blue box.\n\n\u003cimg src=\"https://github.com/AvraamMavridis/react-intersection-visible-hook/blob/master/demo_gif.gif?raw=true\" /\u003e\n\n*Demo and tests are coming*\n\n```\nimport useVisibility from 'react-intersection-visible-hook'\n```\n\n### How to use it\n\n```js\nfunction App() {\n  const nodeRef = useRef(null);\n  const visibility = useVisibility(nodeRef);\n\n  return (\n    \u003cdiv className=\"App\" ref={nodeRef}\u003e\n      \u003ch1\u003eHello\u003c/h1\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\n##### With options\n\n```js\nconst options = {\n  root: document.querySelector('#scrollArea'),\n  rootMargin: '0px',\n  threshold: 1.0\n}\n\nfunction App() {\n  const nodeRef = useRef(null);\n  const visibility = useVisibility(nodeRef, options);\n\n  return (\n    \u003cdiv className=\"App\" ref={nodeRef}\u003e\n      \u003ch1\u003eHello\u003c/h1\u003e\n      \u003ch2\u003e{visibility.isIntersecting ?  'Component is visible' : 'Component is hidden' }\u003c/h2\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\nThe `visibility` object contains\n\n```\nboundingClientRect\nintersectionRatio\nintersectionRect\nisIntersecting\nrootBounds\ntarget\ntime\n```\n\n\n### Contribute\n\nAny pull-request is more than welcome :boom: :smile:\n\n### License\n\nMIT\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favraammavridis%2Freact-intersection-visible-hook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favraammavridis%2Freact-intersection-visible-hook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favraammavridis%2Freact-intersection-visible-hook/lists"}