useLockBodyScroll
Will lock body and prevent it from being scrolled. Useful when showing a modal or anything else when you don't want the user to be able to scroll the body. From useHooks.
Usage
import React from 'react';import { useLockBodyScroll } from '@fransvilhelm/hooks';const Modal = ({ children }) => {useLockBodyScroll();return <div>{children}</div>;};
Example
Parameters
useLockBodyScroll
accepts two parameters.
Param | Type | Required | Default | Description |
---|---|---|---|---|
lock | boolean | false | true | Wether to apply the lock or not |
ref | RefObject\<HTMLElement> | false | useRef(document.body) | A ref object pointing to an element to lock scrolling on |
Returns
useLockBodyScroll
returns nothing