{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "use-in-view",
  "title": "Use In View",
  "description": "A hook that tracks whether an element is visible in the viewport using IntersectionObserver.",
  "files": [
    {
      "path": "registry/hooks/use-in-view.tsx",
      "content": "'use client'\n\nimport { useLayoutEffect, useRef, useState } from 'react'\n\ninterface UseInViewOptions {\n  /** From 0 to 1, 1 by default. */\n  threshold?: number\n  /** @default '0px' */\n  rootMargin?: string\n}\n\nexport function useInView(options: UseInViewOptions = {}) {\n  const { rootMargin = '0px', threshold = 1.0 } = options\n\n  const ref = useRef<HTMLElement | null>(null)\n  const [isInView, setIsInView] = useState(false)\n\n  useLayoutEffect(() => {\n    const element = ref.current\n    if (!element) return\n\n    const observer = new IntersectionObserver(\n      (entries) => {\n        const latest = entries.at(-1)\n        if (latest) setIsInView(latest.isIntersecting)\n      },\n      { threshold, rootMargin },\n    )\n\n    observer.observe(element)\n\n    return () => {\n      observer.disconnect()\n    }\n  }, [rootMargin, threshold])\n\n  return {\n    isInView,\n    ref,\n  }\n}\n",
      "type": "registry:hook",
      "target": "@hooks/use-in-view.tsx"
    }
  ],
  "type": "registry:hook"
}
