vkorobtsev-nextJs/app/about/components/quote/useIntersectionObserver.js
Alvalen Shafel 7f0c142dda
Refactor and update project components for Next.js 15 compatibility (#6)
* refactor: update all modules to latest version

* refactor: update layout to match nextjs 15 convention

* fix: implement TopProgressBar as Client

* fix: remove unnecessary locale prop

* fix: update postcss.config.js export

* fix: comment out styles

* fix: ref usage in useIntersectionObserver and update Navbar

* chore: performance optimizations

* fix: simplify Loading component structure

* refactor: move ProjectCard component and add prop types validation
2025-03-18 12:39:32 +07:00

34 lines
683 B
JavaScript

// useIntersectionObserver.js
import { useEffect, useState, useRef } from "react";
export function useIntersectionObserver() {
const [isIntersecting, setIsIntersecting] = useState(false);
const ref = useRef(null);
useEffect(() => {
const observer = new IntersectionObserver(
([entry]) => {
setIsIntersecting(entry.isIntersecting);
},
{
root: null,
rootMargin: "0px",
threshold: 0.1,
}
);
const currentRef = ref.current; // Store the ref value in a variable
if (currentRef) {
observer.observe(currentRef);
}
return () => {
if (currentRef) {
observer.unobserve(currentRef);
}
};
}, []);
return [ref, isIntersecting];
}