Skip to content

useScrollLock

Category
Export Size
751 B
Last Changed
5 days ago

Lock scrolling of the element

Demo

Usage

tsx
import { 
useScrollLock
} from '@reause/core'
import {
useRef
} from 'react'
const
el
=
useRef
<HTMLDivElement>(null)
const [
isLocked
,
setIsLocked
] =
useScrollLock
(
el
)
setIsLocked
(true) // lock
setIsLocked
(false) // unlock

Type Declarations

ts
export type ScrollLockElement = HTMLElement | SVGElement | Window | Document | null | undefined

export type ScrollLockTarget = RefObject<ScrollLockElement>

export type UseScrollLockReturn = [
    isLocked: boolean,
    setIsLocked: (value: boolean) => void
]

export function useScrollLock(element: ScrollLockTarget, initialState?): UseScrollLockReturn

Source

Source · Demo · VueUse

Contributors

hairyf

Changelog

v0.1.0 on
9451e - fix(core): resolve useScrollLock audit findings (#637)
8fddc - chore!: remove all Vue-only Maybe* types and getter unions, adopt React Ref (#462)

Released under the MIT License. v0.1.8