Overview
The SolidJS adapter provides hooks and components that integrate drag and drop functionality into your Solid applications with fine-grained reactivity and excellent performance.Installation
Install the Solid package and its dependencies:Requirements: SolidJS 1.8.0 or higher
Getting Started
1
Add DragDropProvider
Wrap your application with the
DragDropProvider component: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 theuseSortable hook:
Hook APIs
useDraggable
TheuseDraggable hook signature from /home/daytona/workspace/source/packages/solid/src/core/draggable/useDraggable.ts:15:
useDroppable
TheuseDroppable hook signature from /home/daytona/workspace/source/packages/solid/src/core/droppable/useDroppable.ts:14:
useSortable
TheuseSortable hook signature from /home/daytona/workspace/source/packages/solid/src/sortable/useSortable.ts:18:
Advanced Features
Drag Handles
Use separate elements for dragging:Modifiers
Constrain drag behavior:Sensors
Customize activation:Type Safety
Define custom data types:Fine-Grained Reactivity
Solid’s fine-grained reactivity means updates are surgical:Performance Optimization
Leverage Solid’s reactivity for optimal performance:Best Practices
- Stable IDs: Use consistent, unique IDs for draggables and droppables
- Signals: Return getters (functions) for reactive state like
isDragging() - For component: Always use
<For>for lists to optimize reconciliation - Memoization: Use
createMemofor expensive derived values - Effects: Use
createEffectto respond to drag state changes
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