Skip to main content

useItemContext

Access per-item drag state from within a SortableItem's children. Returns SharedValues for building custom animated styles.

Import

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

Usage

import { useItemContext } from 'react-native-drax';
import Reanimated, { useAnimatedStyle } from 'react-native-reanimated';

function ItemContent({ label }) {
const { isActive } = useItemContext();

const animatedStyle = useAnimatedStyle(() => ({
transform: [{ scale: isActive.value ? 1.1 : 1 }],
shadowOpacity: isActive.value ? 0.3 : 0,
shadowRadius: isActive.value ? 8 : 0,
shadowColor: '#000',
}));

return (
<Reanimated.View style={animatedStyle}>
<Text>{label}</Text>
</Reanimated.View>
);
}

Return Value

PropertyTypeDescription
itemKeystringThis item's key (from keyExtractor)
indexnumberCurrent display index
isActiveSharedValue<boolean>true when THIS item is being dragged
activeItemIdSharedValue<string>ID of the currently dragged item (empty if none)

Requirements

Must be called within a SortableItem. Throws if used outside.