diff --git a/src/shared/components/about-counter.tsx b/src/shared/components/about-counter.tsx index f18617f..319fc62 100644 --- a/src/shared/components/about-counter.tsx +++ b/src/shared/components/about-counter.tsx @@ -1,40 +1,16 @@ 'use client'; import { Users } from 'lucide-react'; -import { useEffect, useRef, useState } from 'react'; import { useTextController } from '@/shared/language/hooks/use-text-controller'; +import { useIntersectionObserver } from '../hooks/use-intersection-observer'; import AnimatedCounter from './animated-counter'; export default function AboutCounter() { - const [isVisible, setIsVisible] = useState(false); - const sectionRef = useRef(null); - const { t } = useTextController(); - useEffect(() => { - const observer = new IntersectionObserver( - (entries) => { - const [entry] = entries; - if (entry.isIntersecting) { - setIsVisible(true); - observer.disconnect(); - } - }, - { - threshold: 0.1, - }, - ); - - if (sectionRef.current) { - observer.observe(sectionRef.current); - } - - return () => { - observer.disconnect(); - }; - }, []); + const { sectionRef, isVisible } = useIntersectionObserver(); return (
() => { + const [isVisible, setIsVisible] = useState(false); + const sectionRef = useRef(null); + + useEffect(() => { + const observer = new IntersectionObserver( + (entries) => { + const [entry] = entries; + if (entry.isIntersecting) { + setIsVisible(true); + observer.disconnect(); + } + }, + { + threshold: 0.1, + }, + ); + + if (sectionRef.current) { + observer.observe(sectionRef.current); + } + + return () => { + observer.disconnect(); + }; + }, []); + + return { sectionRef, isVisible }; +}; diff --git a/src/widgets/stats-section.tsx b/src/widgets/stats-section.tsx index f63db3f..c3c57f4 100644 --- a/src/widgets/stats-section.tsx +++ b/src/widgets/stats-section.tsx @@ -1,40 +1,15 @@ 'use client'; -import { useEffect, useRef, useState } from 'react'; - import { Container } from '@/shared/components/container'; +import { useIntersectionObserver } from '@/shared/hooks/use-intersection-observer'; import { useTextController } from '@/shared/language/hooks/use-text-controller'; import AnimatedCounter from '../shared/components/animated-counter'; export function StatsSection() { - const [isVisible, setIsVisible] = useState(false); - const sectionRef = useRef(null); - const { t } = useTextController(); - useEffect(() => { - const observer = new IntersectionObserver( - (entries) => { - const [entry] = entries; - if (entry.isIntersecting) { - setIsVisible(true); - observer.disconnect(); - } - }, - { - threshold: 0.1, - }, - ); - - if (sectionRef.current) { - observer.observe(sectionRef.current); - } - - return () => { - observer.disconnect(); - }; - }, []); + const { sectionRef, isVisible } = useIntersectionObserver(); return (