add basic theme upload functionality

This commit is contained in:
SethBurkart123
2024-05-21 21:36:20 +10:00
parent c9c357bec2
commit 438af68b9f
4 changed files with 129 additions and 4 deletions
@@ -0,0 +1,34 @@
import { useState, useEffect, useRef } from 'react';
interface Options {
root?: Element | null;
rootMargin?: string;
threshold?: number | number[];
}
type UseVisibilityReturnType = [any | null, boolean];
const useVisibility = (options: Options): UseVisibilityReturnType => {
const [isVisible, setIsVisible] = useState<boolean>(false);
const elementRef = useRef<Element | null>(null);
useEffect(() => {
const observer = new IntersectionObserver(([entry]) => {
setIsVisible(entry.isIntersecting);
}, options);
if (elementRef.current) {
observer.observe(elementRef.current);
}
return () => {
if (elementRef.current) {
observer.unobserve(elementRef.current);
}
};
}, [elementRef, options]);
return [elementRef, isVisible];
};
export default useVisibility;