update global (texte + logo)
This commit is contained in:
20
Linkwarden/hooks/useOnScreen.tsx
Normal file
20
Linkwarden/hooks/useOnScreen.tsx
Normal file
@ -0,0 +1,20 @@
|
||||
import { RefObject, useEffect, useMemo, useState } from "react";
|
||||
|
||||
export default function useOnScreen(ref: RefObject<HTMLElement>) {
|
||||
const [isIntersecting, setIntersecting] = useState(false);
|
||||
|
||||
const observer = useMemo(
|
||||
() =>
|
||||
new IntersectionObserver(([entry]) =>
|
||||
setIntersecting(entry.isIntersecting)
|
||||
),
|
||||
[ref]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
observer.observe(ref.current as HTMLElement);
|
||||
return () => observer.disconnect();
|
||||
}, []);
|
||||
|
||||
return isIntersecting;
|
||||
}
|
Reference in New Issue
Block a user