MCPcopy Create free account
hub / github.com/ecto/muni / useInView

Function useInView

web/src/components/home/hooks/useInView.ts:5–22  ·  view source on GitHub ↗
(margin = "200px")

Source from the content-addressed store, hash-verified

3import { useRef, useState, useEffect } from "react";
4
5export function useInView(margin = "200px"): [React.RefObject<HTMLDivElement>, boolean] {
6 const ref = useRef<HTMLDivElement>(null);
7 const [inView, setInView] = useState(false);
8
9 useEffect(() => {
10 const el = ref.current;
11 if (!el) return;
12
13 const observer = new IntersectionObserver(
14 ([entry]) => setInView(entry.isIntersecting),
15 { rootMargin: margin }
16 );
17 observer.observe(el);
18 return () => observer.disconnect();
19 }, [margin]);
20
21 return [ref, inView];
22}

Callers 3

ExplodedViewerFunction · 0.90
VcadViewerFunction · 0.90
RoverViewerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected