Skip to contents

useDragMonitor

Observe every drag on the page without being a source or a drop target.

MonitorWaiting for a drag

useDragMonitor runs callbacks for every drag on the page. A monitor has no element and renders nothing. It only observes, so no provider is required.

Use it for a status bar, analytics, shared drag state, or committing an update from one place instead of each target’s onDrop. In the shape sorter above, the cutouts only declare what they accept. A monitor updates the live status and places each shape after a successful drop.

A monitor registers once for the component’s lifetime. Re-renders do not register it again, and Base UI reads the latest callbacks for every event. A monitor mounted during a drag observes the rest of that drag.

Filter by kind

accept declares which kinds a monitor observes. Pass one kind or an array. Base UI evaluates it when the monitor joins a drag, either at drag start or when a monitor mounts during a drag. If accept excludes that drag, the monitor ignores the rest of it.

Observe only cards

The accepted kinds determine the type of source.payload. An array produces a union that each kind’s matches method can narrow. Omit accept to observe every drag with an unknown payload. Return early from callbacks to apply more specific filters.

Drag events

A monitor’s event handlers are optional. Each receives the drag source, location history, and mode, which is either 'pointer' or 'keyboard':

Reacting to every stage of a drag

Every handler receives the event payload first. Its second argument, eventDetails, contains the reason and native event.

Monitors do not receive onDragEnter or onDragLeave, which belong to drop targets. onDragEnd fires whenever the drag ends. onDrop fires only after a successful drop.

Use Draggable.useActiveDrag to read the active source without event handlers. It re-renders only when a drag starts or ends. Outside React, use useDragDropManager and its registerMonitor method.

API reference

Observes every drag operation that matches accept, regardless of which element started it. Use it for status indicators, analytics, or committing a reorder on drop.

parameters*WithInferredAccept< UseDragMonitorParameters<TPayload | unknown>, AnyDragAccept >
Type

Return value

useDragMonitor.ParametersHide

useDragMonitor.ReturnValueHide