UNPKG

@kiwicom/orbit-components

Version:

Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.

21 lines (18 loc) 562 B
import { useLayoutEffect } from "react"; import { disableBodyScroll, clearAllBodyScrollLocks } from "body-scroll-lock"; var useLockScrolling = function useLockScrolling(ref) { var lock = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; useLayoutEffect(function () { if (ref.current) { if (lock) { disableBodyScroll(ref.current); } else { clearAllBodyScrollLocks(); } } return function () { clearAllBodyScrollLocks(); }; }, [ref, lock]); }; export default useLockScrolling;