{"id":17157751,"url":"https://github.com/lessp/react-is-visible","last_synced_at":"2025-04-13T13:26:49.688Z","repository":{"id":38424883,"uuid":"130121659","full_name":"lessp/react-is-visible","owner":"lessp","description":"A small library for React to know if an element is on screen or not","archived":false,"fork":false,"pushed_at":"2023-03-07T13:10:11.000Z","size":5736,"stargazers_count":28,"open_issues_count":12,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T06:39:18.554Z","etag":null,"topics":["intersection-observer","react","visibility"],"latest_commit_sha":null,"homepage":"https://lessp.github.io/react-is-visible/","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/lessp.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-04-18T21:03:42.000Z","updated_at":"2024-06-27T07:30:18.000Z","dependencies_parsed_at":"2024-06-18T17:08:26.625Z","dependency_job_id":"12b1d352-bef1-4d61-93ed-baefdbd077e8","html_url":"https://github.com/lessp/react-is-visible","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lessp%2Freact-is-visible","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lessp%2Freact-is-visible/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lessp%2Freact-is-visible/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lessp%2Freact-is-visible/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lessp","download_url":"https://codeload.github.com/lessp/react-is-visible/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248719641,"owners_count":21150779,"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":["intersection-observer","react","visibility"],"created_at":"2024-10-14T22:09:41.654Z","updated_at":"2025-04-13T13:26:49.667Z","avatar_url":"https://github.com/lessp.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React Is Visible\n\n[![build status](https://img.shields.io/travis/lessp/react-is-visible/master.svg?style=flat-square)](https://travis-ci.org/lessp/react-is-visible)\n[![dependencies Status](https://david-dm.org/lessp/react-is-visible/status.svg?style=flat-square)](https://david-dm.org/lessp/react-is-visible)\n\nA small library that lets you know whether a component is visible on screen or not.\n\nUses the [IntersectionObserver API](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver).\n\n### Live Examples\n\n**Storybook:** [https://lessp.github.io/react-is-visible/](https://lessp.github.io/react-is-visible/index.html)\n\n**Code Sandbox:** [https://2c2qy.csb.app/](https://2c2qy.csb.app/)\n\n[![Edit festive-mendel-2c2qy](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/festive-mendel-2c2qy?fontsize=14\u0026hidenavigation=1\u0026theme=dark)\n\n# Table of Contents\n\n1. [Polyfill](#polyfill)\n2. [Installation](#installation)\n3. [Usage](#usage)\n   - [React Hook](#react-hook)\n   - [HOC](#hoc)\n   - [Render Prop](#render-prop)\n4. [License](#license)\n\n## [Polyfill](#polyfilll)\n\nIn order to polyfill, install the [polyfill from W3C](https://github.com/w3c/IntersectionObserver/tree/master/polyfill)\n\n    $ npm install intersection-observer --save\n\n... and import it before importing `'react-is-visible'`\n\neg.\n\n```jsx\n// App.js\nimport React from 'react'\nimport ReactDOM from 'react-dom'\n\nimport 'intersection-observer'\nimport { withIsVisible } from 'react-is-visible'\n\n// ...\n```\n\n## [Installation](#installation)\n\n    $ npm install react-is-visible --save\n\nor\n\n    $ yarn add react-is-visible\n\n## [Usage](#usage)\n\n### React Is Visible\n\n#### [React Hook](#react-hook)\n\n```jsx\nimport React, { useRef } from 'react'\nimport { useIsVisible } from 'react-is-visible'\n\nconst SomeComponent = () =\u003e {\n  const nodeRef = useRef()\n  const isVisible = useIsVisible(nodeRef)\n  /* const isVisible = useIsVisible(nodeRef, { once: true }) */\n\n  return \u003ch1 ref={nodeRef}\u003e{isVisible \u0026\u0026 `I'm visible!`}\u003c/h1\u003e\n}\n```\n\n#### [HOC](#hoc)\n\n```jsx\nimport React from 'react'\nimport { withIsVisible } from 'react-is-visible'\n\nconst SomeComponent = ({ isVisible }) =\u003e \u003ch1\u003e{isVisible \u0026\u0026 `I'm visible!`}\u003c/h1\u003e\n\nexport default withIsVisible(SomeComponent)\n/* export default withIsVisible(SomeComponent, { once: true }) */\n```\n\nor as a decorator\n\n```jsx\nimport React from 'react'\nimport { withIsVisible } from 'react-is-visible'\n\n@withIsVisible\nclass SomeClass extends React.Component {\n  render() {\n    const { isVisible } = this.props\n\n    return \u003ch1\u003e{isVisible \u0026\u0026 `I'm visible!`}\u003c/h1\u003e\n  }\n}\n```\n\n#### [Render Prop](#render-prop)\n\nThe `once`-prop is optional, but if passed, the `isVisible`-flag will only trigger once.\n\n```jsx\nimport React from 'react'\nimport IsVisible from 'react-is-visible'\n\nconst App = () =\u003e (\n  \u003cIsVisible once\u003e\n    {(isVisible) =\u003e \u003ch1\u003e{isVisible ? `I'm visible!` : `I'm not visible!`}\u003c/h1\u003e}\n  \u003c/IsVisible\u003e\n)\n```\n\n## [License](#license)\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flessp%2Freact-is-visible","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flessp%2Freact-is-visible","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flessp%2Freact-is-visible/lists"}