use-draggable-scroll
Version:
React hook to add draggability to scrollable content easily
34 lines (23 loc) • 654 B
Markdown
React hook to add draggability to scrollable content easily.

```tsx
import { useDraggableScroll } from 'use-draggable-scroll';
const Component = () => {
const ref = useRef(null);
const { onMouseDown } = useDraggableScroll(ref);
return (
<div ref={ref} onMouseDown={onMouseDown}>
<div>child 1</div>
<div>child 2</div>
<div>child 3</div>
</div>
);
};
```
You can specify the drag direction that is allowed (`vertical`, `horizontal` or `both`(default))
```tsx
const { onMouseDown } = useDraggableScroll(ref, { direction: 'vertical' });
```