Socket
Socket
Sign inDemoInstall

@ash/use-intersection-observer

Package Overview
Dependencies
3
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @ash/use-intersection-observer

``` npm i @ash/use-intersection-observer ```


Version published
Weekly downloads
3
Maintainers
1
Install size
14.1 kB
Created
Weekly downloads
 

Readme

Source

useIntersectionObserver

npm i @ash/use-intersection-observer

Most Intersection Observer helpers are geared towards tracking a single element. This hook is designed for observing multiple elements.

Usage

The useIntersectionObserver hook returns an object with the following entries:

addRef: (component, id: EntryId) => void

Call addRef from a component ref to begin tracking the underlying HTML element.

EntryId is a string or number used to uniquely identify the HTML element.

intersecting: Set

A Set containing all of the EntryIds that are currently intersecting.

Example

import useIntersectionObserver from 'use-intersection-observer'

const App = () => {
  const { addRef, intersecting } = useIntersectionObserver()
  const users = ['Louise', 'Bob', 'Linda']

  return (
    <ul>
      {users.map(name => (
        <li
          key={name}
          ref={component => addRef(component, name)}
        >
          {name}
        </li>
      ))}
    </ul>
  )
}

FAQs

Last updated on 17 Feb 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc