useScrollLock
Freezes background scroll while an overlay is open.
Signature
useScrollLock locks scrolling while its flag is true. Cleanup releases the lock. The hook returns no value.
function useScrollLock(enabled: boolean): void;Usage
import type { ReactNode } from "react";
import { useScrollLock } from "@solarius/onset";
function Modal({ open, children }: { open: boolean; children: ReactNode }) {
useScrollLock(open);
return open ? <div className="backdrop">{children}</div> : null;
}