1.5.2 • Published 4 years ago

use-draggable v1.5.2

Weekly downloads
1,253
License
-
Repository
github
Last release
4 years ago

react-draggable

Travis (.org) npm npm GitHub

A custom hook to make elements draggable.

Usage

Simplest usage:

import { useDraggable } from 'use-draggable';

function MyComponent(props) {
  const { targetRef } = useDraggable({ controlStyle: true });

  return (
    <div ref={targetRef}>
      <h1>You can drag me :)</h1>
    </div>
  );
}

Usage in a class component:

import React from 'react';
import { Draggable } from 'use-draggable';

class MyComponent extends React.Component {
  render() {
    return (
      <Draggable>
        {({ targetRef, handleRef }) => (
          <div ref={targetRef}>
            <h1>You can drag me :)</h1>
            <button ref={handleRef}>with this handle</button>
          </div>
        )}
      </Draggable>
    );
  }
}

Live demo

https://codesandbox.io/s/use-draggable-demo-tiu3w

Contribute

PRs are welcomed! Note - when opening a PR, make sure the last commit message abides commitizen guidelines.

1.5.2

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.1

4 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago