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.

ParamTypeRequiredDefaultDescription
lockboolean falsetrueWether to apply the lock or not
refRefObject\<HTMLElement>falseuseRef(document.body)A ref object pointing to an element to lock scrolling on

Returns

useLockBodyScroll returns nothing