/
foult080
/
hackaton-app
Обзор
Документация
Войти
/
foult080
/
hackaton-app
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
web-app/src/hooks/useInView.ts
26 строк
637 B
Foult080
feat(): new fixes
07 июл 2026, 11:17
07 июл 2026, 11:17
8111f1c
Код
Авторство
О чём код?
import { useState, useEffect, useRef, type RefObject } from 'react' export function useInView(threshold = 0.1): [RefObject<HTMLElement | null>, boolean] { const ref = useRef<HTMLElement | null>(null) const [visible, setVisible] = useState(false) useEffect(() => { const el = ref.current if (!el) return const observer = new IntersectionObserver( ([entry]) => { if (entry.isIntersecting) { setVisible(true) observer.disconnect() } }, { threshold } ) observer.observe(el) return () => observer.disconnect() }, [threshold]) return [ref, visible] }