-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Type checking + minor improvements useScroll
- Loading branch information
Showing
3 changed files
with
34 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
# `useScroll` | ||
|
||
React sensor hook that re-renders on when scroll position in a DOM element changes. | ||
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 element = React.useRef(null); | ||
const {x, y} = useScroll(element); | ||
const scrollRef = React.useRef(null); | ||
const {x, y} = useScroll(scrollRef); | ||
|
||
return ( | ||
<div ref={element}> | ||
<div ref={scrollRef}> | ||
<div>x: {x}</div> | ||
<div>y: {y}</div> | ||
</div> | ||
); | ||
}; | ||
``` | ||
|
||
## Reference | ||
|
||
```ts | ||
useScroll(ref: RefObject<HTMLElement>); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters