Usage
TheuseDroppable hook requires an id and accepts all the same options as the Droppable class. Refer to the Input section below for more information.
API Reference
The
useDroppable hook is a thin wrapper around the Droppable class that makes it easier to create droppable targets in React. It therefore accepts all of the same input arguments.Input
TheuseDroppable hook accepts the following arguments:
string | number
required
The identifier of the droppable element. Should be unique within the same drag and drop context provider.
Element | Ref<Element>
If you already have a reference to the element, you can pass it to the
element option instead of using the ref that is returned by the useDroppable hook to connect the droppable target element.Type | Type[] | ((source: Draggable) => boolean)
Restrict which draggables can be dropped on this target. Pass a single
type, an array of types, or a predicate that receives the draggable and returns true to accept it. If omitted, the droppable accepts every draggable.string | number | Symbol
An optional identifier to categorize this droppable. Whether a draggable can be dropped on this target is determined by this droppable’s own
accept rule checked against the draggable’s type — a droppable’s type is not consulted by accept rules.(input: CollisionDetectorInput) => Collision | null
Optionally supply a collision detector function that can be used to detect collisions between the droppable element and draggable elements.
number
Optionally supply a number to set the collision priority of the droppable element. The higher the number, the higher the priority when detecting collisions. This can be useful if there are multiple droppable elements that overlap.
boolean
Set to
true to prevent the droppable element from being a drop target.{[key: string]: any}
The data argument is for advanced use-cases where you may need access to additional data about the droppable element in event handlers, modifiers, sensors or custom plugins.
() => Effect[]
This is an advanced feature and should not need to be used by most consumers.
useDroppable hook is unmounted.Output
TheuseDroppable hook returns an object containing the following properties:
(element: Element) => void
A ref callback function that can be attached to the element that you want to use as a droppable target.
boolean
A boolean value that indicates whether the element is currently a drop target.