Skip to content

Latest commit

Β 

History

History
31 lines (22 loc) Β· 613 Bytes

useLockBodyScroll.md

File metadata and controls

31 lines (22 loc) Β· 613 Bytes

useLockBodyScroll

React side-effect hook that locks scrolling on the body element. Useful for modal and other overlay components.

Usage

import {useLockBodyScroll, useToggle} from 'react-use';

const Demo = () => {
  const [locked, toggleLocked] = useToggle(false)

  useLockBodyScroll(locked);

  return (
    <div>
      <button onClick={() => toggleLocked()}>
        {locked ? 'Unlock' : 'Lock'}
      </button>
    </div>
  );
};

Reference

useToggle(enabled?: boolean = true);
  • enabled β€” Hook will lock scrolling on the body element if true, defaults to true