Skip to main content
The useSortable hook combines draggable and droppable functionality to create sortable list items. It’s specifically designed for building sortable lists, grids, and other reorderable collections.

Usage

Parameters

string | number
required
Unique identifier for this sortable item.
number
required
Current position of this item in the sortable list. This is used to calculate transitions and reordering.
string
required
Group identifier that links sortable items together. Items with the same group can be reordered among each other.
Element | RefObject<Element>
The DOM element for this sortable item. If not provided, use the ref from the return value.
Element | RefObject<Element>
A specific element to use as the drag handle. If provided, dragging can only be initiated from this element.
Element | RefObject<Element>
The target element for drop detection. Useful for sortable items with complex layouts where the drop target differs from the visual element.
T
Custom data to attach to this sortable item.
boolean
default:"false"
Whether this sortable item is disabled. Disabled items cannot be dragged or act as drop targets.
string
Type identifier for this sortable. Can be used to restrict which items can be sorted together.
string | string[]
Type or types of draggables this sortable accepts as drop targets.
TransitionConfig
Animation configuration for the sortable transition effects.
CollisionDetector
Custom collision detection algorithm for this sortable.
number
Priority for collision detection when multiple sortables overlap. Higher values have higher priority.
Sensor[]
Override the sensors for this specific sortable. By default, inherits from DragDropProvider.
Modifier[]
Modifiers that transform the position during drag. Applied in addition to provider-level modifiers.
Plugin[]
Plugins specific to this sortable. Applied in addition to provider-level plugins.
{x: number, y: number}
Alignment point for the drag source, relative to the element’s position. Values are percentages (0-1).

Return Value

(element: Element | null) => void
Callback ref to attach to the sortable element.
(element: Element | null) => void
Callback ref to attach to a drag handle element.
(element: Element | null) => void
Callback ref to attach to the drop target element (if different from the main element).
(element: Element | null) => void
Callback ref to attach to the drag source element (for advanced use cases).
Sortable<T>
The underlying Sortable instance. Access this for advanced use cases.
boolean
Whether this element is currently being dragged.
boolean
Whether this element is in the dropping animation phase.
boolean
Whether this element is the source of the current drag operation.
boolean
Whether this element is currently the target of a drag operation.

Examples

Basic Sortable List

Sortable with Drag Handle

Multiple Sortable Lists

Sortable Grid

Sortable with Custom Transitions

Type Safety

Use TypeScript generics to type the custom data: