npm.io
0.1.0 • Published 5 years ago

use-draggable-scroll

Licence
MIT
Version
0.1.0
Deps
0
Size
24 kB
Vulns
0
Weekly
0
Stars
35

use-draggable-scroll

React hook to add draggability to scrollable content easily.

Usage

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>
  );
};

Optional parameters

You can specify the drag direction that is allowed (vertical, horizontal or both(default))

const { onMouseDown } = useDraggableScroll(ref, { direction: 'vertical' });

Keywords