diff --git a/src/hooks/useInview.ts b/src/hooks/useInview.ts index a342edb..bd1a162 100644 --- a/src/hooks/useInview.ts +++ b/src/hooks/useInview.ts @@ -9,13 +9,14 @@ const useInView = (options?: IntersectionObserverInit) => { setInView(entry.isIntersecting); }, options); - if (ref.current) { - observer.observe(ref.current); + const currentRef = ref.current; + if (currentRef) { + observer.observe(currentRef); } return () => { - if (ref.current) { - observer.unobserve(ref.current); + if (currentRef) { + observer.unobserve(currentRef); } }; }, [options]);