Files
9ffa2394-a668-4481-8f2d-3aa…/src/components/navbar/NavbarLayoutFloatingOverlay/useScrollDetection.ts
Nikolay Pecheniev 620d7b95fd Initial commit
2025-12-23 17:42:06 +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;
};