Skip to main content

useDraxMethods

Imperative methods for querying and controlling the Drax provider state. Must be called within a DraxProvider.

Import

import { useDraxMethods } from 'react-native-drax';

Usage

function MyComponent() {
const { isDragging, getDroppedItems, clearDroppedItems } = useDraxMethods();

return (
<Button
title="Clear all drops"
onPress={() => clearDroppedItems()}
/>
);
}

Methods

MethodReturn TypeDescription
isDragging()booleanCheck if a drag is currently active
getDraggedId()string | undefinedGet the ID of the currently dragged view
getDroppedItems(receiverId?)Map | SetGet dropped items for a receiver (or all)
clearDroppedItems(receiverId?)voidClear tracking for capacity reset
requestPositionUpdate()voidTrigger re-measurement of all views

Examples

Capacity with manual reset

<DraxView
capacity={3}
onReceiveDragDrop={({ dragged }) => {
addItem(dragged.payload);
}}
/>

// Later, when items are removed:
const { clearDroppedItems } = useDraxMethods();
clearDroppedItems('my-drop-zone-id');

Conditional UI based on drag state

const { isDragging } = useDraxMethods();

// Show trash zone only during drag
{isDragging() && <TrashZone />}