UNPKG

@huse/scroll-lock

Version:

--- title: README nav: title: Hooks path: /hook group: title: Scroll Lock path: /scroll-lock order: 1 ---

26 lines 870 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useScrollLock = void 0; const react_1 = require("react"); function useScrollLock(lock) { const previousOverflowRef = react_1.useRef(''); react_1.useEffect(() => { if (!lock) { return; } /* istanbul ignore next */ if (typeof document === 'undefined') { return; } previousOverflowRef.current = document.body.style.overflow; document.body.style.overflow = 'hidden'; return () => { // Do not reset if other scripts modify style. if (document.body.style.overflow === 'hidden') { document.body.style.overflow = previousOverflowRef.current; } }; }, [lock]); } exports.useScrollLock = useScrollLock; //# sourceMappingURL=index.js.map