Files
songs2vid/hooks/useInView.ts
T
Atakan Doğan ÖzbanandCursor c8015937f9 Align preview typography with FFmpeg output, add video/song title split, and ship OSS updates.
Separate YouTube video titles from on-video song/artist fields with Pro gating, serve curated fonts and watermark assets for 1:1 preview parity, and include billing/API/docs/deploy stack for self-hosted release.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-27 16:26:19 +02:00

41 lines
883 B
TypeScript

"use client";
import { useEffect, useRef, useState } from "react";
type Options = {
threshold?: number;
rootMargin?: string;
once?: boolean;
};
export function useInView<T extends HTMLElement = HTMLDivElement>({
threshold = 0.15,
rootMargin = "0px 0px -40px 0px",
once = true,
}: Options = {}) {
const ref = useRef<T>(null);
const [inView, setInView] = useState(false);
useEffect(() => {
const el = ref.current;
if (!el) return;
const observer = new IntersectionObserver(
([entry]) => {
if (entry.isIntersecting) {
setInView(true);
if (once) observer.unobserve(el);
} else if (!once) {
setInView(false);
}
},
{ threshold, rootMargin },
);
observer.observe(el);
return () => observer.disconnect();
}, [threshold, rootMargin, once]);
return { ref, inView };
}