{"id":20678787,"url":"https://github.com/olistic/react-use-visibility","last_synced_at":"2025-04-19T23:33:36.888Z","repository":{"id":46930067,"uuid":"155619229","full_name":"olistic/react-use-visibility","owner":"olistic","description":"React hook for tracking components visibility","archived":false,"fork":false,"pushed_at":"2023-01-04T02:07:53.000Z","size":599,"stargazers_count":26,"open_issues_count":12,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-19T23:33:32.402Z","etag":null,"topics":["hooks","react"],"latest_commit_sha":null,"homepage":null,"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/olistic.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-31T20:28:13.000Z","updated_at":"2023-12-20T07:07:21.000Z","dependencies_parsed_at":"2023-02-01T17:45:38.908Z","dependency_job_id":null,"html_url":"https://github.com/olistic/react-use-visibility","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/olistic%2Freact-use-visibility","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olistic%2Freact-use-visibility/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olistic%2Freact-use-visibility/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olistic%2Freact-use-visibility/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/olistic","download_url":"https://codeload.github.com/olistic/react-use-visibility/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249830836,"owners_count":21331355,"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","react"],"created_at":"2024-11-16T21:22:15.682Z","updated_at":"2025-04-19T23:33:36.860Z","avatar_url":"https://github.com/olistic.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-use-visibility\n\nReact hook for tracking components visibility.\n\n[![Travis][build-badge]][build] [![Codecov][codecov-badge]][codecov]\n\n![Demo](https://user-images.githubusercontent.com/5600126/47879786-42fc5700-de00-11e8-8ffc-70ff651b4a8b.gif)\n\n\u003e _Electrons becoming excited as they enter the screen._\n\n## Installation\n\n```sh\n$ npm install --save react-use-visibility\n```\n\nAdditionally, you'll need to install version `16.7.0-alpha.0` of `react` and\n`react-dom` since this package relies on\n[React Hooks](https://reactjs.org/hooks):\n\n```sh\n$ npm install --save react@16.7.0-alpha.0 react-dom@16.7.0-alpha.0\n```\n\n\u003e **DISCLAIMER:** React Hooks are an experimental proposal. The Hooks API, as\n\u003e well as this library's, are unstable and subject to change.\n\n## Usage\n\n```js\nimport React, { useRef } from 'react';\nimport useVisibility from 'react-use-visibility';\n\nfunction Electron() {\n  // Use a ref to attach to the element whose visibility you want to keep track of.\n  const imgRef = useRef();\n\n  // `current` points to the mounted img element.\n  const isVisible = useVisibility(imgRef.current);\n\n  return (\n    \u003cimg\n      ref={imgRef}\n      src={electron}\n      className={isVisible ? 'excited' : ''}\n      alt=\"an electron\"\n    /\u003e\n  );\n}\n```\n\n## API Reference\n\n### `useVisibility`\n\n```js\nconst isVisible = useVisibility(el, options);\n```\n\nAccepts a React element as the first argument (`el`) and returns whether it is\non the screen or not.\n\nOptionally, you can pass a second argument to `useVisibility` that is an object\nwith the following properties:\n\n- `partial` (_boolean_): Whether to consider the element visible when only a\n  part of it is on the screen. Defaults to `false`.\n- `scrollableEl` (_Element_): The parent element triggering the scroll event.\n  Defaults to `window`.\n\n[build-badge]:\n  https://img.shields.io/travis/olistic/react-use-visibility/master.svg\n[build]: https://travis-ci.org/olistic/react-use-visibility\n[codecov-badge]:\n  https://img.shields.io/codecov/c/github/olistic/react-use-visibility/master.svg\n[codecov]: https://codecov.io/gh/olistic/react-use-visibility\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folistic%2Freact-use-visibility","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Folistic%2Freact-use-visibility","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folistic%2Freact-use-visibility/lists"}