• Custom React hook that disables scrolling for a specified element or window.

    This hook listens for scroll events on the specified element or window, and when a scroll event occurs, it resets the scroll position to the top left corner, effectively preventing any scrolling from occurring.

    Example

    const MyComponent = () => {
    const ref = useRef<HTMLDivElement>(null);

    useScrollLock(ref);

    return <div ref={ref} style={{ overflow: 'auto', height: '200px' }}>Scrollable Content</div>;
    };

    Parameters

    • ref: THookEventElement<Element | Window>

      A reference to the target element or window to lock scrolling on.

    • Optional props: IUseScrollLockProps

      Optional settings for managing the event listener behavior.

    Returns void