mirror of
https://github.com/streamich/react-use.git
synced 2025-12-08 18:02:14 +00:00
32 lines
621 B
Markdown
32 lines
621 B
Markdown
# `useLockBodyScroll`
|
|
|
|
React side-effect hook that locks scrolling on the body element. Useful for modal and other overlay components.
|
|
|
|
## Usage
|
|
|
|
```jsx
|
|
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
|
|
|
|
```ts
|
|
useLockBodyScroll(enabled?: boolean = true);
|
|
```
|
|
|
|
- `enabled` — Hook will lock scrolling on the body element if `true`, defaults to `true`
|