Fix Scroll.

This commit is contained in:
2025-02-10 12:53:25 +01:00
parent 4b74640d87
commit d23c381913
10 changed files with 454 additions and 129 deletions
+34
View File
@@ -0,0 +1,34 @@
// hooks/useScrollLock.ts
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import { useScrollContext } from '../components/ScrollContext';
export const useScrollLock = (lock: boolean) => {
const location = useLocation();
const { isTransitioning, lockScroll, unlockScroll } = useScrollContext();
// Handle lock state changes
useEffect(() => {
if (lock && !isTransitioning) {
lockScroll();
} else {
unlockScroll();
}
}, [lock, isTransitioning, lockScroll, unlockScroll]);
// Handle location changes
useEffect(() => {
const timeout = setTimeout(() => {
unlockScroll();
window.scrollTo(0, 0);
}, 100);
return () => clearTimeout(timeout);
}, [location.pathname, unlockScroll]);
// Cleanup on unmount
useEffect(() => {
return () => {
unlockScroll();
};
}, [unlockScroll]);
};