mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {useEffect} from 'react' 2import {isWeb} from '#/platform/detection' 3 4let refCount = 0 5 6function incrementRefCount() { 7 if (refCount === 0) { 8 document.body.style.overflow = 'hidden' 9 document.documentElement.style.scrollbarGutter = 'auto' 10 } 11 refCount++ 12} 13 14function decrementRefCount() { 15 refCount-- 16 if (refCount === 0) { 17 document.body.style.overflow = '' 18 document.documentElement.style.scrollbarGutter = '' 19 } 20} 21 22export function useWebBodyScrollLock(isLockActive: boolean) { 23 useEffect(() => { 24 if (!isWeb || !isLockActive) { 25 return 26 } 27 incrementRefCount() 28 return () => decrementRefCount() 29 }) 30}