MCPcopy Create free account
hub / github.com/Dark-Brain07/PayForApi / useIntersectionObserver

Function useIntersectionObserver

hooks/useIntersectionObserver.ts:8–22  ·  view source on GitHub ↗
(ref: RefObject<Element>, options?: IntersectionObserverInit)

Source from the content-addressed store, hash-verified

6 * @param options Intersection observer options
7 */
8export function useIntersectionObserver(ref: RefObject<Element>, options?: IntersectionObserverInit) {
9 const [isIntersecting, setIsIntersecting] = useState(false);
10 useEffect(() => {
11 const target = ref.current;
12 if (!target) return;
13 const observer = new IntersectionObserver(([entry]) => {
14 setIsIntersecting(entry.isIntersecting);
15 }, options);
16 observer.observe(target);
17 return () => {
18 observer.unobserve(target);
19 };
20 }, [ref, options]);
21 return isIntersecting;
22}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected