useLockBodyScroll

Temporarily disable scrolling on the document body with useLockBodyScroll.

Install:

npm i @uidotdev/usehooks

Description:

The useLockBodyScroll hook temporarily disables scrolling on the document body. This can be beneficial in scenarios where you want to restrict scrolling while displaying a modal, a dropdown menu, or any other component that requires the user’s focus. Once the component using this hook is unmounted or no longer needed, the hook returns a cleanup function that restores the original overflow style, ensuring that the scroll behavior is reverted to its previous state.

Demo:

Example:

More Hooks:

Sort: