Download frontend/src/components/landing/useInViewAnimation.js from tamgaa/app: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/spaces/tamgaa/app/resolve/main/frontend/src/components/landing/useInViewAnimation.js
- Command line
-
hf download hf://spaces/tamgaa/app/frontend/src/components/landing/useInViewAnimation.js
-
curl -L -o useInViewAnimation.js https://huggingface.co/spaces/tamgaa/app/resolve/main/frontend/src/components/landing/useInViewAnimation.js
1.07 kB
| import { useEffect, useRef, useState } from "react"; | |
| // Studio landing scroll-reveal hook (SHARED CONTRACT). | |
| // Returns [ref, inView]. IntersectionObserver, threshold 0.1, fires once. | |
| // Consumers: className={inView ? "st-fade-up" : "st-hidden"} | |
| // style={{ animationDelay: "0.Xs" }} | |
| export default function useInViewAnimation() { | |
| const ref = useRef(null); | |
| const [inView, setInView] = useState(false); | |
| useEffect(() => { | |
| const node = ref.current; | |
| if (!node) return undefined; | |
| // No observer support (old browsers / test envs): show content immediately. | |
| if (typeof IntersectionObserver === "undefined") { | |
| setInView(true); | |
| return undefined; | |
| } | |
| const observer = new IntersectionObserver( | |
| (entries) => { | |
| entries.forEach((entry) => { | |
| if (entry.isIntersecting) { | |
| setInView(true); | |
| observer.disconnect(); | |
| } | |
| }); | |
| }, | |
| { threshold: 0.1 } | |
| ); | |
| observer.observe(node); | |
| return () => observer.disconnect(); | |
| }, []); | |
| return [ref, inView]; | |
| } | |