Files
9166dbca-8ce0-4bb8-ba2e-566…/src/components/navbar/NavbarLayoutFloatingOverlay/useScrollDetection.ts
2026-01-01 13:13:26 +02:00

18 lines
582 B
TypeScript

import { useState, useEffect } from 'react';
import { throttle } from '@/utils/throttle';
export const useScrollDetection = (threshold: number = 50) => {
const [isScrolled, setIsScrolled] = useState(false);
useEffect(() => {
const handleScroll = throttle(() => {
setIsScrolled(window.scrollY > threshold);
}, 100);
handleScroll();
window.addEventListener('scroll', handleScroll, { passive: true });
return () => window.removeEventListener('scroll', handleScroll);
}, [threshold]);
return isScrolled;
};