perfect-postcode/frontend/src/hooks/useFadeIn.ts
2026-02-02 21:56:35 +00:00

21 lines
519 B
TypeScript

import { useRef, useEffect } from 'react';
export function useFadeInRef() {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
const el = ref.current;
if (!el) return;
const observer = new IntersectionObserver(
([entry]) => {
if (entry.isIntersecting) {
el.classList.add('fade-in-visible');
observer.unobserve(el);
}
},
{ threshold: 0.15 }
);
observer.observe(el);
return () => observer.disconnect();
}, []);
return ref;
}