Shadcn Hooks

useScrollLock

A hook to lock the scroll of the body

Loading...

Installation

npx shadcn@latest add @shadcnhooks/use-scroll-lock

API

interface UseScrollLockOptions {
  autoLock?: boolean
  lockTarget?: HTMLElement | string
  widthReflow?: boolean
}

interface UseScrollLockReturn {
  isLocked: boolean
  lock: () => void
  unlock: () => void
}

/**
 * A hook to lock the scroll of the body
 * @param options - The options for the hook
 * @param options.autoLock - Whether to automatically lock the scroll when the component is mounted
 * @param options.lockTarget - The target element to lock the scroll on
 * @param options.widthReflow - Whether to reflow the width of the body when the scroll is locked
 * @returns The scroll lock state and the functions to lock and unlock the scroll
 */
function useScrollLock(options?: UseScrollLockOptions): UseScrollLockReturn

Credits

Last updated on

On this page