react-dnd, react-draggable, and react-zoom-pan-pinch are React libraries that enable rich user interactions, but they address fundamentally different use cases. react-dnd provides a comprehensive drag-and-drop framework for transferring data between designated drop targets, commonly used in task boards or file organizers. react-draggable offers simple, direct control for making any element draggable anywhere on the screen, ideal for floating UI components like modals or widgets. react-zoom-pan-pinch implements multi-touch gestures — including zoom, pan, and pinch — for navigating large visual content such as maps, diagrams, or images. While all involve manipulating elements on screen, their underlying models, APIs, and intended scenarios differ significantly.
When building interactive UIs in React — think Kanban boards, diagram editors, or image viewers — you’ll often need to support drag-and-drop, free dragging, or zooming/panning. The three libraries react-dnd, react-draggable, and react-zoom-pan-pinch each solve distinct interaction problems. Despite all involving "moving things around," they’re built for different use cases, with different mental models and APIs. Let’s compare them head-to-head.
react-dnd is a drag-and-drop framework inspired by the HTML5 Drag and Drop API but built entirely in JavaScript. It’s designed for transferring data between drop targets, like moving a card from one column to another. It uses a provider-based context system and separates concerns into drag sources and drop targets.
// react-dnd: Moving an item between lists
import { useDrag, useDrop } from 'react-dnd';
const Item = ({ id, moveItem }) => {
const [{ isDragging }, drag] = useDrag(() => ({
type: 'item',
item: { id },
collect: (monitor) => ({ isDragging: !!monitor.isDragging() })
}));
return <div ref={drag} style={{ opacity: isDragging ? 0.5 : 1 }}>Drag me</div>;
};
const DropZone = ({ acceptType, onDrop }) => {
const [{ isOver }, drop] = useDrop(() => ({
accept: acceptType,
drop: (item) => onDrop(item),
collect: (monitor) => ({ isOver: !!monitor.isOver() })
}));
return <div ref={drop} style={{ background: isOver ? '#eee' : '#fff' }}>Drop here</div>;
};
react-draggable enables free-form dragging of a single element anywhere on the screen. It doesn’t care about drop zones or data transfer — it just lets you move something and gives you position updates. Think resizable modals, draggable avatars, or movable widgets.
// react-draggable: Move an element freely
import Draggable from 'react-draggable';
function Widget() {
return (
<Draggable>
<div style={{ width: 100, height: 100, background: 'blue' }} />
</Draggable>
);
}
// Or with callbacks
<Draggable
onStop={(e, data) => console.log('Final position:', data.x, data.y)}
>
<div>Draggable Box</div>
</Draggable>
react-zoom-pan-pinch adds multi-touch gestures (zoom, pan, pinch) to any container. It’s ideal for maps, diagrams, or image viewers where users need to explore a large canvas. It manages internal state for scale and position and exposes controls via a render prop or hook.
// react-zoom-pan-pinch: Interactive canvas navigation
import { TransformWrapper, TransformComponent } from 'react-zoom-pan-pinch';
function ImageViewer({ src }) {
return (
<TransformWrapper>
{({ zoomIn, zoomOut, resetTransform }) => (
<>
<div>
<button onClick={() => zoomIn()}>+</button>
<button onClick={() => zoomOut()}>–</button>
<button onClick={() => resetTransform()}>Reset</button>
</div>
<TransformComponent>
<img src={src} alt="Zoomable" />
</TransformComponent>
</>
)}
</TransformWrapper>
);
}
Each library handles internal state differently, which affects how much control you have.
react-dnd keeps drag state in React Context (via <DndProvider>). You don’t manage coordinates directly — instead, you respond to drop events with payload data. Positional feedback (like previews) is handled via its built-in backend system (HTML5, Touch, or custom).
react-draggable gives you full access to the current {x, y} position through callbacks (onDrag, onStop) or by controlling the component yourself with position and onDrag. It’s unopinionated about rendering — you provide the DOM node.
react-zoom-pan-pinch encapsulates all transform state (scale, x, y) internally but exposes it via the render prop or useTransformContext hook. You can read or update it programmatically:
// Accessing transform state
<TransformWrapper>
{({ state: { scale, positionX, positionY } }) => (
<div>Scale: {scale.toFixed(2)}</div>
)}
</TransformWrapper>
You need to drag cards between columns, with visual feedback during drag and data updates on drop.
react-dndA UI element that users can reposition anywhere on the page, but doesn’t interact with other elements.
react-draggableUsers need to zoom into details, pan across a large SVG or image, and possibly reset the view.
react-zoom-pan-pinchreact-dnd for free dragging. It’s overkill if you don’t need drop targets or data transfer. You’ll fight its abstractions.react-draggable for list reordering. It doesn’t handle collision detection, auto-scrolling, or drop logic — you’d have to build all that yourself.react-zoom-pan-pinch for drag-and-drop. It has no concept of “dropping” items or transferring data between zones.Yes — and sometimes you need to. For example, a diagram editor might use:
react-zoom-pan-pinch for canvas navigationreact-draggable for moving individual nodes within the canvasreact-dnd for importing new nodes from a sidebar paletteIn such cases, ensure event propagation doesn’t conflict (e.g., dragging a node shouldn’t also pan the canvas). Libraries like react-zoom-pan-pinch offer pansDisabled or event filtering to help.
| Feature | react-dnd | react-draggable | react-zoom-pan-pinch |
|---|---|---|---|
| Primary Use Case | Data transfer between zones | Free movement of elements | Zoom/pan/pinch on content |
| State Ownership | Context-managed | Callback-driven or controlled | Internal + exposed via hook |
| Drop Logic | ✅ Built-in | ❌ Not applicable | ❌ Not applicable |
| Gesture Support | Basic (via backends) | Mouse/touch drag only | ✅ Multi-touch, wheel, keys |
| Best For | Lists, grids, reorderable UI | Floating UI, modals, widgets | Maps, images, large canvases |
Ask yourself: What is the user trying to accomplish?
react-dnd.react-draggable.react-zoom-pan-pinch.These libraries solve orthogonal problems. Picking the right one avoids unnecessary complexity and keeps your interaction code clean, maintainable, and performant.
Choose react-draggable when you need to make a single element freely draggable anywhere on the page without drop targets or data transfer — for example, movable chat widgets, resizable panels, or floating toolbars. It’s lightweight, requires minimal setup, and gives you direct access to position updates, but doesn’t support collision detection, auto-scrolling, or list reordering natively.
Choose react-dnd when you need structured drag-and-drop interactions with clear source and target semantics, such as reordering items in a list, moving cards between columns, or transferring data between UI zones. It handles accessibility, preview rendering, and backend abstraction (HTML5, touch) out of the box, but is overkill if you only need free-form dragging without drop logic.
Choose react-zoom-pan-pinch when users need to explore large visual content through zooming, panning, and pinch gestures, such as in map viewers, diagram editors, or image galleries. It provides smooth, performant gesture handling with keyboard and mouse support, but is not designed for drag-and-drop or element repositioning outside of canvas navigation.
A simple component for making elements draggable.
<Draggable>
<div>I can now be moved around!</div>
</Draggable>
| Version | Compatibility |
|---|---|
| 4.x | React 16.3+ |
| 3.x | React 15-16 |
| 2.x | React 0.14 - 15 |
| 1.x | React 0.13 - 0.14 |
| 0.x | React 0.10 - 0.13 |
$ npm install react-draggable
If you aren't using browserify/webpack, a
UMD version of react-draggable is available. It is updated per-release only.
This bundle is also what is loaded when installing from npm. It expects external React and ReactDOM.
If you want a UMD version of the latest master revision, you can generate it yourself from master by cloning this
repository and running $ make. This will create umd dist files in the dist/ folder.
The default export is <Draggable>. At the .DraggableCore property is <DraggableCore>.
Here's how to use it:
// ES6
import Draggable from 'react-draggable'; // The default
import {DraggableCore} from 'react-draggable'; // <DraggableCore>
import Draggable, {DraggableCore} from 'react-draggable'; // Both at the same time
// CommonJS
let Draggable = require('react-draggable');
let DraggableCore = Draggable.DraggableCore;
<Draggable>A <Draggable> element wraps an existing element and extends it with new event handlers and styles.
It does not create a wrapper element in the DOM.
Draggable items are moved using CSS Transforms. This allows items to be dragged regardless of their current positioning (relative, absolute, or static). Elements can also be moved between drags without incident.
If the item you are dragging already has a CSS Transform applied, it will be overwritten by <Draggable>. Use
an intermediate wrapper (<Draggable><span>...</span></Draggable>) in this case.
View the Demo and its source for more.
import React from 'react';
import ReactDOM from 'react-dom';
import Draggable from 'react-draggable';
class App extends React.Component {
eventLogger = (e: MouseEvent, data: Object) => {
console.log('Event: ', e);
console.log('Data: ', data);
};
render() {
return (
<Draggable
axis="x"
handle=".handle"
defaultPosition={{x: 0, y: 0}}
position={null}
grid={[25, 25]}
scale={1}
onStart={this.handleStart}
onDrag={this.handleDrag}
onStop={this.handleStop}>
<div>
<div className="handle">Drag from here</div>
<div>This readme is really dragging on...</div>
</div>
</Draggable>
);
}
}
ReactDOM.render(<App/>, document.body);
The <Draggable/> component transparently adds draggability to its children.
Note: Only a single child is allowed or an Error will be thrown.
For the <Draggable/> component to correctly attach itself to its child, the child element must provide support
for the following props:
style is used to give the transform css to the child.className is used to apply the proper classes to the object being dragged.onMouseDown, onMouseUp, onTouchStart, and onTouchEnd are used to keep track of dragging state.React.DOM elements support the above properties by default, so you may use those elements as children without any changes. If you wish to use a React component you created, you'll need to be sure to transfer prop.
<Draggable> Props://
// Types:
//
type DraggableEventHandler = (e: Event, data: DraggableData) => void | false;
type DraggableData = {
node: HTMLElement,
// lastX + deltaX === x
x: number, y: number,
deltaX: number, deltaY: number,
lastX: number, lastY: number
};
//
// Props:
//
{
// If set to `true`, will allow dragging on non left-button clicks.
allowAnyClick: boolean,
// Default `false` and default behavior before 4.5.0.
// If set to `true`, the 'touchstart' event will not be prevented,
// which will allow scrolling inside containers. We recommend
// using the 'handle' / 'cancel' props when possible instead of enabling this.
//
// See https://github.com/react-grid-layout/react-draggable/issues/728
allowMobileScroll: boolean,
// Determines which axis the draggable can move. This only affects
// flushing to the DOM. Callbacks will still include all values.
// Accepted values:
// - `both` allows movement horizontally and vertically (default).
// - `x` limits movement to horizontal axis.
// - `y` limits movement to vertical axis.
// - 'none' stops all movement.
axis: string,
// Specifies movement boundaries. Accepted values:
// - `parent` restricts movement within the node's offsetParent
// (nearest node with position relative or absolute), or
// - a selector, restricts movement within the targeted node
// - An object with `left, top, right, and bottom` properties.
// These indicate how far in each direction the draggable
// can be moved.
bounds: {left?: number, top?: number, right?: number, bottom?: number} | string,
// Specifies a selector to be used to prevent drag initialization. The string is passed to
// Element.matches, so it's possible to use multiple selectors like `.first, .second`.
// Example: '.body'
cancel: string,
// Class names for draggable UI.
// Default to 'react-draggable', 'react-draggable-dragging', and 'react-draggable-dragged'
defaultClassName: string,
defaultClassNameDragging: string,
defaultClassNameDragged: string,
// Specifies the `x` and `y` that the dragged item should start at.
// This is generally not necessary to use (you can use absolute or relative
// positioning of the child directly), but can be helpful for uniformity in
// your callbacks and with css transforms.
defaultPosition: {x: number, y: number},
// If true, will not call any drag handlers.
disabled: boolean,
// Default `true`. Adds "user-select: none" while dragging to avoid selecting text.
enableUserSelectHack: boolean,
// Specifies the x and y that dragging should snap to.
grid: [number, number],
// Specifies a selector to be used as the handle that initiates drag.
// Example: '.handle'
handle: string,
// If desired, you can provide your own offsetParent for drag calculations.
// By default, we use the Draggable's offsetParent. This can be useful for elements
// with odd display types or floats.
offsetParent: HTMLElement,
// Called whenever the user mouses down. Called regardless of handle or
// disabled status.
onMouseDown: (e: MouseEvent) => void,
// Called when dragging starts. If `false` is returned any handler,
// the action will cancel.
onStart: DraggableEventHandler,
// Called while dragging.
onDrag: DraggableEventHandler,
// Called when dragging stops.
onStop: DraggableEventHandler,
// If running in React Strict mode, ReactDOM.findDOMNode() is deprecated.
// Unfortunately, in order for <Draggable> to work properly, we need raw access
// to the underlying DOM node. If you want to avoid the warning, pass a `nodeRef`
// as in this example:
//
// function MyComponent() {
// const nodeRef = React.useRef(null);
// return (
// <Draggable nodeRef={nodeRef}>
// <div ref={nodeRef}>Example Target</div>
// </Draggable>
// );
// }
//
// This can be used for arbitrarily nested components, so long as the ref ends up
// pointing to the actual child DOM node and not a custom component.
//
// For rich components, you need to both forward the ref *and props* to the underlying DOM
// element. Props must be forwarded so that DOM event handlers can be attached.
// For example:
//
// const Component1 = React.forwardRef(function (props, ref) {
// return <div {...props} ref={ref}>Nested component</div>;
// });
//
// const nodeRef = React.useRef(null);
// <DraggableCore onDrag={onDrag} nodeRef={nodeRef}>
// <Component1 ref={nodeRef} />
// </DraggableCore>
//
// Thanks to react-transition-group for the inspiration.
//
// `nodeRef` is also available on <DraggableCore>.
nodeRef: React.Ref<typeof React.Component>,
// Much like React form elements, if this property is present, the item
// becomes 'controlled' and is not responsive to user input. Use `position`
// if you need to have direct control of the element.
position: {x: number, y: number}
// A position offset to start with. Useful for giving an initial position
// to the element. Differs from `defaultPosition` in that it does not
// affect the position returned in draggable callbacks, and in that it
// accepts strings, like `{x: '10%', y: '10%'}`.
positionOffset: {x: number | string, y: number | string},
// Specifies the scale of the canvas your are dragging this element on. This allows
// you to, for example, get the correct drag deltas while you are zoomed in or out via
// a transform or matrix in the parent of this element.
scale: number
}
Note that sending className, style, or transform as properties will error - set them on the child element
directly.
<Draggable> is a 'batteries-included' component that manages its own state. If you want to completely
control the lifecycle of the component, use <DraggableCore>.
For some users, they may want the nice state management that <Draggable> provides, but occasionally want
to programmatically reposition their components. <Draggable> allows this customization via a system that
is similar to how React handles form components.
If the prop position: {x: number, y: number} is defined, the <Draggable> will ignore its internal state and use
the provided position instead. Alternatively, you can seed the position using defaultPosition. Technically, since
<Draggable> works only on position deltas, you could also seed the initial position using CSS top/left.
We make one modification to the React philosophy here - we still allow dragging while a component is controlled.
We then expect you to use at least an onDrag or onStop handler to synchronize state.
To disable dragging while controlled, send the prop disabled={true} - at this point the <Draggable> will operate
like a completely static component.
<DraggableCore>For users that require absolute control, a <DraggableCore> element is available. This is useful as an abstraction
over touch and mouse events, but with full control. <DraggableCore> has no internal state.
See React-Resizable and React-Grid-Layout for some usage examples.
<DraggableCore> is a useful building block for other libraries that simply want to abstract browser-specific
quirks and receive callbacks when a user attempts to move an element. It does not set styles or transforms
on itself and thus must have callbacks attached to be useful.
<DraggableCore> takes a limited subset of options:
{
allowAnyClick: boolean,
allowMobileScroll: boolean,
cancel: string,
disabled: boolean,
enableUserSelectHack: boolean,
offsetParent: HTMLElement,
grid: [number, number],
handle: string,
onStart: DraggableEventHandler,
onDrag: DraggableEventHandler,
onStop: DraggableEventHandler,
onMouseDown: (e: MouseEvent) => void,
scale: number
}
Note that there is no start position. <DraggableCore> simply calls drag handlers with the below parameters,
indicating its position (as inferred from the underlying MouseEvent) and deltas. It is up to the parent
to set actual positions on <DraggableCore>.
Drag callbacks (onStart, onDrag, onStop) are called with the same arguments as <Draggable>.
$ npm run dev$ npm testmake release-patch, make release-minor, or make-release-majormake publishMIT