k8ordo
  • UI
  • Form
  • State
  • Router
  • Static
  • Server
Switch to dark mode
  • Get Started
  • Theming
  • i18n
  • Components
  • Hooks
  • Helpers
  • AI
Open navigation
DOM Interaction
  • useClickAway
  • useHover
  • useResize
  • useScrollDirection
  • useScrollLock
  • useWindowResize
  • useWritingMode
State & Storage
  • useClipboard
  • useControllableState
Timing
  • useDebouncedTransition
  • useDeferredDebounce
  • useInterval
  • useTimeout
Utility
  • useBreakpoint
  • useClient
  • useDisclosure
  • useStep
  • useWindowSize
Observer
  • useIntersectionObserver
  • useInView
k8ordo

React libraries that use Baseline features without holding back.

Packages
  • @k8ordo/ui
  • @k8ordo/form
  • @k8ordo/state
  • @k8ordo/router
  • @k8ordo/static
  • @k8ordo/server
UI
  • Get Started
  • Theming
  • i18n
  • Components
  • Hooks
  • Helpers
  • AI Chat
  • Generative UI
  • AI Agents
  • Storybook
Resources
  • GitHub
  • npm

© 2026 k8o — MIT License

Typeset in Noto Sans JP & M PLUS 2

Hooks

DOM Interaction
  • useClickAway
  • useHover
  • useResize
  • useScrollDirection
  • useScrollLock
  • useWindowResize
  • useWritingMode
State & Storage
  • useClipboard
  • useControllableState
Timing
  • useDebouncedTransition
  • useDeferredDebounce
  • useInterval
  • useTimeout
Utility
  • useBreakpoint
  • useClient
  • useDisclosure
  • useStep
  • useWindowSize
Observer
  • useIntersectionObserver
  • useInView

useScrollLock

A hook that locks and unlocks scroll on the body or a specified element.

Import

Usage

Basic Usage

This page's body does not scroll, so the behavior can't be tried here. Please verify on an actual scrollable page.

Target element

Try scrolling this area. Pressing Lock area stops scrolling for this element only.

Parameters

target
Type: RefObject<HTMLElement | null>
Default: document.body
PropTypeDefault
targetRefObject<HTMLElement | null>document.body

Return Value

lock
Type: () => void
Default: -
unlock
Type: () => void
Default: -
PropTypeDefault
lock() => void-
unlock() => void-
import { useScrollLock } from '@k8ordo/ui';
const { lock, unlock } = useScrollLock();

return (
  <div>
    <button onClick={lock}>Lock</button>
    <button onClick={unlock}>Unlock</button>
  </div>
);
const scrollRef = useRef<HTMLDivElement>(null);
const { lock, unlock } = useScrollLock(scrollRef);

return (
  <div>
    <button onClick={lock}>Lock area</button>
    <button onClick={unlock}>Unlock area</button>
    <div ref={scrollRef} style={{ overflow: 'auto', height: 128 }}>
      {/* scrollable content */}
    </div>
  </div>
);