Skip to content

useScrollHide

The useScrollHide hook allows you to hide the scrollbars of a specified HTML element or the body of the document. This can be useful for modals or overlays where you want to prevent background scrolling.

Add the utility

Terminal window
npx @ivnatsr/ezreact add use-scroll-hide

Return

This hook returns a ref that should be attached to the element whose scroll behavior you want to control. If you don’t attach this ref to any DOM element, it will default to body.

Example

import { useScrollHide } from './path/to/use-scroll-hide'
const ScrollHideExample = () => {
const elementRef = useScrollHide()
return (
<div ref={elementRef}>
<h1>Content with hidden scrollbars</h1>
<p>Scrollbars are hidden for this element.</p>
</div>
)
}
export default ScrollHideExample