mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at rn-stack-repro 28 lines 530 B view raw
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 } 10 refCount++ 11} 12 13function decrementRefCount() { 14 refCount-- 15 if (refCount === 0) { 16 document.body.style.overflow = '' 17 } 18} 19 20export function useWebBodyScrollLock(isLockActive: boolean) { 21 useEffect(() => { 22 if (!isWeb || !isLockActive) { 23 return 24 } 25 incrementRefCount() 26 return () => decrementRefCount() 27 }) 28}