https://github.com/andarist/use-smooth-scroll
React hook which gives a smooth scrolling function.
https://github.com/andarist/use-smooth-scroll
hook hooks react reactjs scroll
Last synced: about 1 year ago
JSON representation
React hook which gives a smooth scrolling function.
- Host: GitHub
- URL: https://github.com/andarist/use-smooth-scroll
- Owner: Andarist
- Created: 2018-11-05T18:48:07.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-06T11:07:38.000Z (about 7 years ago)
- Last Synced: 2024-05-02T00:09:42.522Z (about 2 years ago)
- Topics: hook, hooks, react, reactjs, scroll
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 41
- Watchers: 3
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# use-smooth-scroll
React hook which gives a smooth scrolling function.
## Example ([Codesandbox](https://codesandbox.io/s/github/Andarist/use-smooth-scroll/tree/master/examples/simple))
```js
const Example = () => {
const ref = React.useRef()
const scrollTo = useSmoothScroll('x', ref)
return (
<>
scrollTo(getRandomScrollTarget(ref.current))}>
Click me
{range(100).map(i => (
))}
>
)
}
```