MCPcopy Create free account
hub / github.com/ampproject/amphtml / useIsInViewport

Function useIsInViewport

src/preact/component/intersection-observer.js:43–63  ·  view source on GitHub ↗
(ref, ioOptions)

Source from the content-addressed store, hash-verified

41 * @return {boolean}
42 */
43export function useIsInViewport(ref, ioOptions) {
44 const [isInViewport, setIsInViewport] = useState(false);
45
46 useEffect(() => {
47 const node = ref.current;
48 if (!node) {
49 return;
50 }
51
52 const unobserve = observeIntersections(
53 node,
54 (entry) => {
55 setIsInViewport(entry.isIntersecting);
56 },
57 ioOptions
58 );
59 return unobserve;
60 }, [ref, ioOptions]);
61
62 return isInViewport;
63}

Callers 1

BentoListWithRefFunction · 0.90

Calls 1

observeIntersectionsFunction · 0.90

Tested by

no test coverage detected