@stackmeister/react-use-intersection-observer
TypeScript icon, indicating that this package has built-in type declarations

0.1.5 • Public • Published

@stackmeister/react-use-intersection-observer

A hook that wraps around the DOM IntersectionObserver.

With it you can check things like "for how many percent is this element in that element" or "am I scrolled half over this element".

Install

// Yarn
yarn add @stackmeister/react-use-intersection-observer

// NPM
npm i @stackmeister/react-use-intersection-observer

TypeScript typings are included (No @types/ package needed)

Usage

import useIntersectionObserver from '@stackmeister/react-use-intersection-observer'

const App = () => {
  const { ref, entry } = useIntersectionObserver()

  // entry =
  // {
  //   boundingClientRect: DOMRect,
  //   intersectionRatio: number,
  //   intersectionRect: DOMRect,
  //   isIntersecting: boolean,
  //   rootBounds: DOMRect,
  //   time: number,
  // }

  return (
    <div ref={ref}>
      ...
    </div>
  )
}

Readme

Keywords

none

Package Sidebar

Install

npm i @stackmeister/react-use-intersection-observer

Weekly Downloads

8

Version

0.1.5

License

MIT

Unpacked Size

8.05 kB

Total Files

7

Last publish

Collaborators

  • torbenkoehn