Skip to main content

useDropZone

Create an zone where files can be dropped

Usage

Live Editor
function Demo() {
  const ref = useRef<HTMLDivElement>(null);

  const isOver = useDropZone(ref, (_files) => {});
  return (
    <div>
      <p>Drop files into dropZone</p>
      {/* <img src={logo} alt="" /> */}
      <div
        ref={ref}
        style={{
          minHeight: 200,
          display: "flex",
          alignItems: "center",
          justifyContent: "center",
          marginTop: "1.5rem",
          background: "rgba(156,163,175,0.1)",
        }}
      >
        <div> isOverDropZone: {JSON.stringify(isOver)}</div>
      </div>
    </div>
  );
};

Result
Loading...

API

useDropZone

Returns

boolean: Whether the file is on the zone

Arguments

ArgumentDescriptionTypeDefaultValue
targettarget elementBasicTarget<EventTarget> (Required)-
onDropdrop callback((files: File[] | null) => void) | undefined-

BasicTarget

export type BasicTarget<T extends TargetType = Element> = (() => TargetValue<T>) | TargetValue<T> | MutableRefObject<TargetValue<T>>;

TargetValue

type TargetValue<T> = T | undefined | null;

TargetType

type TargetType = HTMLElement | Element | Window | Document | EventTarget;