UNPKG

@mantine/hooks

Version:

A collection of 50+ hooks for state and UI management

32 lines (31 loc) 799 B
"use client"; let react = require("react"); //#region packages/@mantine/hooks/src/use-intersection/use-intersection.ts function useIntersection(options) { const [entry, setEntry] = (0, react.useState)(null); const observer = (0, react.useRef)(null); return { ref: (0, react.useCallback)((element) => { if (observer.current) { observer.current.disconnect(); observer.current = null; } if (element === null) { setEntry(null); return; } observer.current = new IntersectionObserver(([_entry]) => { setEntry(_entry); }, options); observer.current.observe(element); }, [ options?.rootMargin, options?.root, options?.threshold ]), entry }; } //#endregion exports.useIntersection = useIntersection; //# sourceMappingURL=use-intersection.cjs.map