diff options
-rw-r--r-- | thallium-frontend/src/utils/hooks.ts | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/thallium-frontend/src/utils/hooks.ts b/thallium-frontend/src/utils/hooks.ts index 9b478f7..997f274 100644 --- a/thallium-frontend/src/utils/hooks.ts +++ b/thallium-frontend/src/utils/hooks.ts @@ -1,4 +1,5 @@ -import { useMemo, useState, useEffect } from "react"; +import { useState, useEffect } from "react"; +import { type RefObject } from "react"; export function useVisible(ref: RefObject<HTMLElement>) { const [isVisible, setVisible] = useState(false) @@ -7,7 +8,8 @@ export function useVisible(ref: RefObject<HTMLElement>) { const observer = new IntersectionObserver( ([entry]) => setVisible(entry.isIntersecting) ) - observer.observe(ref.current) + if (ref.current) + observer.observe(ref.current) return () => observer.disconnect() }, []) |