A custom hook to make elements draggable.
import { useDraggable } from 'use-draggable';
function MyComponent(props) {
const { targetRef } = useDraggable({ controlStyle: true });
return (
<div ref={targetRef}>
<h1>You can drag me :)</h1>
</div>
);
}
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>
);
}
}
https://codesandbox.io/s/use-draggable-demo-tiu3w
PRs are welcomed! Note - when opening a PR, make sure the last commit message abides commitizen guidelines.