easy to use hook for intersection observers
npm i use-intersection-observer
import * as React from "react";
import { useIntersectionObserver } from "use-intersection-observer";
const Example = () => {
const { observe } = useIntersectionObserver(entries => {
for (const entry of entries) {
// do stuff with each entry
}
});
return (
<div>
<ul>
<li ref={observe}></li>
<li ref={observe}></li>
<li ref={observe}></li>
</ul>
</div>
);
};
MIT © GypsyDangerous
This hook is created using create-react-hook.