2.0.0 • Published 4 years ago

use-observer-hook v2.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

use-observer

Custom hook for IntersectionOberserver

Installation

npm i use-observer-hook

Usage

Let the hook return the ref for you.

function App() {
  const ref = useObserver(() => {
    // do magic
  });

  return <div ref={ref} />;
}

You can alternatively pass dependencies to the array, much like how React.useEffect works. Then the hook will update accordingly.

function App() {
  const ref = useObserver(() => {
    // do magic
  }, {}, [some, argument]);

  return <div ref={ref} />;
}

Specify options(root, threshold) to the hook

function App() {
  const ref = useObserver(
    () => {
      // do magic
    },
    { root: null, threshold: 1.0 },
    [some, argument],
  );

  return <div ref={ref} />;
}
2.0.0

4 years ago

1.1.0

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago