fn

useDropZone

v0.0.14testeddemo

Create a drag-and-drop file drop zone on a target element or document.

Example

ts
const dropZone = useTemplateRef<HTMLElement>('dropZone');
const { isOverDropZone, files } = useDropZone(dropZone, {
  dataTypes: ['image/png'],
  onDrop: (files) => console.log(files),
});

Demo

Loading demo…

Signature

ts
export function useDropZone(
  target: MaybeComputedElementRef | MaybeRefOrGetter<Document | null | undefined>,
  options: UseDropZoneOptions | UseDropZoneOptions['onDrop'] ={ ... }

Parameters

ParameterTypeDescription
targetMaybeComputedElementRef | MaybeRefOrGetter<Document | null | undefined>The element (or document) acting as the drop zone.
options?UseDropZoneOptions | UseDropZoneOptions['onDrop']Drop zone options, or a shorthand onDrop callback.

Returns

UseDropZoneReturnThe reactive drop zone state.
PropertyTypeDescription
isOverDropZoneShallowRef<boolean>Whether a valid drag is currently hovering over the target.
filesShallowRef<File[] | null>The dropped files, or null when nothing has been dropped yet.
isSupportedComputedRef<boolean>Whether the Drag and Drop API is available in the current environment.