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