Hooks

useScrollLock

Publisher

cermuel

50 hooks published

More from this publisher

useScrollLock

Lock background scrolling without layout shifting.

useScrollLock.tsx
import { useScrollLock } from "@cermuel/hooks/react";export function useScrollLockExample() {  const { locked, lock, unlock } = useScrollLock();  return <button type="button" onClick={locked ? unlock : lock}>{locked ? "Unlock" : "Lock"}</button>;}

Props

Param
Type
Default Value
initial?
boolean
false

Returns

{ locked: boolean; lock: () => void; unlock: () => void; toggle: () => void; }