Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
16 lines (13 sloc) 434 Bytes
import { useEffect, useRef } from 'react';
export default function usePreventScroll(active?: boolean) {
const lastOverflowValue = useRef('');
useEffect(() => {
if (active === undefined || active) {
lastOverflowValue.current = document.body.style.overflow;
document.body.style.overflow = 'hidden';
}
return () => {
document.body.style.overflow = lastOverflowValue.current;
};
}, [active]);
}
You can’t perform that action at this time.