Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
"use client";
import { type RefObject, useEffect, useState } from "react";
/** True while the element is within `margin` of the viewport. */
export function useInView(
ref: RefObject<Element | null>,
margin = "100px",
): boolean {
const [inView, setInView] = useState(false);
useEffect(() => {
const node = ref.current;
if (!node) return;
const observer = new IntersectionObserver(
([entry]) => setInView(entry.isIntersecting),
{ rootMargin: margin },
);
observer.observe(node);
return () => observer.disconnect();
}, [ref, margin]);
return inView;
}