custom hook for IntersectionObserver
npm install use-observer-hook
npm i use-observer-hook
`Usage
Let the hook return the ref for you.
`jsx
function App() {
const ref = useObserver(() => {
// do magic
}); return
;
}
`
You can alternatively pass dependencies to the array,
much like how React.useEffect works. Then the hook will update accordingly.
`jsx
function App() {
const ref = useObserver(() => {
// do magic
}, {}, [some, argument]); return
;
}
`Specify options(root, threshold) to the hook
`jsx
function App() {
const ref = useObserver(
() => {
// do magic
},
{ root: null, threshold: 1.0 },
[some, argument],
); return
;
}
``