{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "use-in-viewport",
  "title": "useInViewport",
  "description": "Fires a callback when an element enters the viewport via IntersectionObserver, with one-shot and repeating modes for lazy sections and infinite-scroll sentinels.",
  "files": [
    {
      "path": "registry/default/hooks/use-in-viewport.ts",
      "content": "import * as React from \"react\";\n\nexport interface UseInViewportOptions {\n  enabled?: boolean;\n  rootMargin?: string;\n  once?: boolean;\n}\n\nexport function useInViewport(\n  node: Element | null,\n  onIntersect: () => void,\n  { enabled = true, rootMargin, once = false }: UseInViewportOptions = {},\n): void {\n  const onIntersectRef = React.useRef(onIntersect);\n  onIntersectRef.current = onIntersect;\n\n  React.useEffect(() => {\n    if (!enabled || !node || typeof IntersectionObserver === \"undefined\") {\n      return;\n    }\n    const observer = new IntersectionObserver(\n      (entries) => {\n        if (entries.some((entry) => entry.isIntersecting)) {\n          onIntersectRef.current();\n          if (once) {\n            observer.disconnect();\n          }\n        }\n      },\n      rootMargin ? { rootMargin } : undefined,\n    );\n    observer.observe(node);\n    return () => observer.disconnect();\n  }, [node, enabled, rootMargin, once]);\n}\n",
      "type": "registry:hook"
    }
  ],
  "type": "registry:hook"
}