Skip to main content

useDraxContext

Access the Drax context value, which contains SharedValues for drag state and methods for view management.

Import

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

Usage

function CustomComponent() {
const { draggedIdSV, receiverIdSV, dragPhaseSV } = useDraxContext();

// Use in animated styles
const style = useAnimatedStyle(() => ({
backgroundColor: dragPhaseSV.value === 'dragging' ? 'red' : 'blue',
}));

return <Reanimated.View style={style} />;
}

Return Value

The hook returns the DraxContextValue with SharedValues and methods. Key fields:

FieldTypeDescription
draggedIdSVSharedValue<string>ID of the currently dragged view
receiverIdSVSharedValue<string>ID of the current receiver
dragPhaseSVSharedValue<DragPhase>'idle' | 'dragging' | 'releasing'
hoverPositionSVSharedValue<Position>Current hover position
hoverReadySVSharedValue<boolean>Whether hover content is rendered
spatialIndexSVSharedValue<SpatialEntry[]>View positions for hit-testing
warning

This is an advanced API. Most use cases are covered by DraxView's callback props and style props. Use useDraxContext only when you need direct access to drag state SharedValues.