feat(global) project init

This commit is contained in:
lumither committed 2024-10-12 23:24:37 -07:00
commit 3556eaed5e
22 files changed
+637

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
import { useEffect, useState } from 'react';
const useScroll = () => {
const [ isScrolledX, setIsScrolledX ] = useState(false);
const [ isScrolledY, setIsScrolledY ] = useState(false);
const [ scrollX, setScrollX ] = useState(0);
const [ scrollY, setScrollY ] = useState(0);
const handleScroll = () => {
const x = window.scrollX;
const y = window.scrollY;
setScrollX(x);
setScrollY(y);
setIsScrolledX(x > 0);
setIsScrolledY(y > 0);
};
useEffect(() => {
window.addEventListener('scroll', handleScroll);
// Cleanup listener on unmount
return () => {
window.removeEventListener('scroll', handleScroll);
};
}, []);
return [ isScrolledX, isScrolledY, scrollX, scrollY ];
};
export default useScroll;