Rooks

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

On this page