2.0.0 • Published 4 years ago
use-observer-hook v2.0.0
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} />;
}