mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
feat: start of monorepo
This commit is contained in:
1 parent
14f39d71ac
commit
73c7bdf0c0
260 files changed
+1236
-1235
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import { RefObject, useEffect, useRef, useState } from 'react';
|
||||
|
||||
/**
|
||||
* Thanks GuCier!
|
||||
*
|
||||
* https://stackoverflow.com/a/65008608/12294756
|
||||
*/
|
||||
export default function useOnScreen(ref: RefObject<HTMLElement>) {
|
||||
const [isIntersecting, setIntersecting] = useState(false);
|
||||
const observer = useRef<IntersectionObserver>();
|
||||
|
||||
useEffect(() => {
|
||||
observer.current = new IntersectionObserver(([entry]) =>
|
||||
setIntersecting(entry.isIntersecting),
|
||||
);
|
||||
}, [ref]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!ref.current) return;
|
||||
|
||||
observer.current?.observe(ref.current);
|
||||
return () => observer.current?.disconnect();
|
||||
}, [ref]);
|
||||
|
||||
return isIntersecting;
|
||||
}
|
||||
Reference in new issue
Block a user