Spaces:
Configuration error
Configuration error
Download src/components/hooks/useSticky.ts from SreejithSHR/umami: direct link, hf CLI and curl.
- Browser
- Download file 724 Bytes
-
https://huggingface.co/spaces/SreejithSHR/umami/resolve/main/src/components/hooks/useSticky.ts
- Command line
-
hf download hf://spaces/SreejithSHR/umami/src/components/hooks/useSticky.ts
-
curl -L -o useSticky.ts https://huggingface.co/spaces/SreejithSHR/umami/resolve/main/src/components/hooks/useSticky.ts
724 Bytes
| import { useState, useEffect, useRef } from 'react'; | |
| export function useSticky({ enabled = true, threshold = 1 }) { | |
| const [isSticky, setIsSticky] = useState(false); | |
| const ref = useRef(null); | |
| useEffect(() => { | |
| let observer: IntersectionObserver | undefined; | |
| const handler: IntersectionObserverCallback = ([entry]) => | |
| setIsSticky(entry.intersectionRatio < threshold); | |
| if (enabled && ref.current) { | |
| observer = new IntersectionObserver(handler, { threshold: [threshold] }); | |
| observer.observe(ref.current); | |
| } | |
| return () => { | |
| if (observer) { | |
| observer.disconnect(); | |
| } | |
| }; | |
| }, [ref, enabled, threshold]); | |
| return { ref, isSticky }; | |
| } | |
| export default useSticky; | |