useLockBodyScroll

About

Locks or unlocks body scroll

Examples

Basic

import { useState } from "react";
import { useLockBodyScroll } from "rooks";
export default function App() {
const [isLocked, setIsLocked] = useState(false);
// Lock body scroll when isLocked is true
useLockBodyScroll(isLocked);
return (
<div>
<button onClick={() => setIsLocked(!isLocked)}>
{isLocked ? "Unlock scroll" : "Lock scroll"}
</button>
</div>
);
}

Arguments

ArgumentTypeDescription
isLockedbooleanWhether to lock or unlock scroll on the body tag

Join the community!

Join our discord server! You can click the floating discord icon at the bottom right of the screen and chat with us!

Powered by vercel