useBodyScroll

Disable scrolling behavior for body or any element, it is useful for displaying popup element or menus.

If the page's scrollbar is set to a user-defined width before scrolling is disabled, a paddingRight value will be added after disabling to adapt.

General

Click button to disable scrolling.

APIs

useBodyScroll

type BodyScrollOptions = {
  delayReset: number  // resume scrolling after a delay, default is 0
}

const useBodyScroll = (
  elementRef?: RefObject<HTMLElement> | null,
  options?: BodyScrollOptions,
) => [boolean, Dispatch<SetStateAction<boolean>>]