Use body scroll

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

This is custom React Hooks, you need to follow the Basic Rules when you use it.


Click button to disable scrolling.



type BodyScrollOptions = {
  scrollLayer: boolean  // whether Ref needs to scroll

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