Skip to main content

Overview

The React adapter provides hooks and components that seamlessly integrate drag and drop into your React applications with full TypeScript support.

Installation

Install the React package and its dependencies:
Requirements: React 18.0.0 or higher

Getting Started

1

Add DragDropProvider

Wrap your application with the DragDropProvider:
2

Create draggable components

Use the useDraggable hook to make elements draggable:
3

Create droppable zones

Use the useDroppable hook to create drop targets:
4

Handle drag events

Listen to events via the provider props:

Complete Example

Here’s a full drag and drop implementation:

Sortable Lists

Create sortable lists with the useSortable hook:

Hook APIs

useDraggable

The useDraggable hook signature from /home/daytona/workspace/source/packages/react/src/core/draggable/useDraggable.ts:21:

useDroppable

The useDroppable hook signature from /home/daytona/workspace/source/packages/react/src/core/droppable/useDroppable.ts:22:

useSortable

The useSortable hook signature from /home/daytona/workspace/source/packages/react/src/sortable/useSortable.ts:23:

Advanced Features

Drag Handles

Use separate elements for dragging:

Modifiers

Constrain drag behavior:

Sensors

Customize activation:

Type Safety

Define custom data types:

Best Practices

  • Stable IDs: Use consistent, unique IDs for draggables and droppables
  • Memoization: Memoize expensive computations in event handlers
  • Ref forwarding: When wrapping components, forward refs properly
  • State updates: Batch state updates in drag event handlers
  • Performance: Use React’s memo/useMemo for large lists

Next Steps

Sortable Lists

Build sortable lists with animations

Multiple Containers

Drag between multiple containers

Sensors

Configure interaction methods

Events

Handle drag and drop events