Easily scroll within an element using hooks!
Add @mariosant/react-sweet-scroll
to your package.json
.
$ npm install @mariosant/react-sweet-scroll
# or
$ yarn add @mariosant/react-sweet-scroll
You can now import the module and use it like
import useScroll from '@mariosant/react-sweet-scroll';
The hook accepts an array with dependencies which work exactly like useEffect
and a set of options, similar to scrollIntoView
.
It returns a component, that should be placed to the point the list container should scroll to.
Consider the example below.
import useScroll from '@mariosant/react-sweet-scroll';
import List from './some-component';
const Component = ({messages}) => {
const ScrollPoint = useScroll([messages]);
return (
<List>
{messages.map(...)}
<ScrollPoint />
</List>
)
};
Marios Antonoudiou – @marios_ant – [email protected]
Distributed under the MIT license.
https://github.com/mariosant/react-sweet-scroll
- Fork it (https://github.com/mariosant/react-sweet-scroll/fork)
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes using a semantic commit message.
- Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request