useDrag
Hook that orchestrates file drag-and-drop events over a container. Returns
the isDragging state and a bundle of handlers ready to be spread onto a
<div>.
Automatically filters files by the types accepted in accept (same format
as the HTML accept attribute) and, optionally, limits to a single file via
single.
When to use
| ✅ Use when… | 🚫 Avoid when… |
|---|---|
|
|
Signature
const { isDragging, events } = useDrag({
accept?: string[];
single?: boolean;
onDragOver?: () => void;
onDragLeave?: () => void;
onDrop?: (files: File[]) => void;
});Example
import { useDrag } from '@apollion-dsi/core/hooks';
function Dropzone({ onDrop }: { onDrop: (files: File[]) => void }) {
const { isDragging, events } = useDrag({
accept: ['image/*', '.pdf'],
onDrop,
});
return (
<div
{...events}
style={{
border: '2px dashed',
borderColor: isDragging ? 'blue' : 'gray',
padding: 24,
}}
>
Drop files here
</div>
);
}See also
useFileDialog— open a file-picker dialog on click.- Full API:
useDrag(reference generated from TSDoc).