mirror of
https://github.com/streamich/react-use.git
synced 2025-12-08 18:02:14 +00:00
28 lines
430 B
Markdown
28 lines
430 B
Markdown
# `useScroll`
|
|
|
|
React sensor hook that re-renders when the scroll position in a DOM element changes.
|
|
|
|
## Usage
|
|
|
|
```jsx
|
|
import {useScroll} from 'react-use';
|
|
|
|
const Demo = () => {
|
|
const scrollRef = React.useRef(null);
|
|
const {x, y} = useScroll(scrollRef);
|
|
|
|
return (
|
|
<div ref={scrollRef}>
|
|
<div>x: {x}</div>
|
|
<div>y: {y}</div>
|
|
</div>
|
|
);
|
|
};
|
|
```
|
|
|
|
## Reference
|
|
|
|
```ts
|
|
useScroll(ref: RefObject<HTMLElement>);
|
|
```
|