As explained stateItem throws an error, and when I console.log stateItem after I set the state it comes out as null. Can someone please tell me why this happens? The code is below:
const [stateItem, setStateItem] = useState(null);
<SwipeListView
data={list}
listKey={'list'}
keyExtractor={list=> list.id}
closeOnScroll={true}
closeOnRowBeginSwipe={true}
renderItem={({ item }) => (
<View>
<TouchableWithoutFeedback
onPress={() => {
setStateItem(item);
>
<View>
<Text>{stateItem.category}</Text>
</View>
</TouchableWithoutFeedback>
</View>
)}
/>
2
Answers
Try :
tested working solution:
<TouchableWithoutFeedback />
component<Pressable />
which i recommend to use at first place anyway.Working example:
In case you HAVE TO use SwipeListView, according to documentation, check following:
If your row is touchable (TouchableOpacity, TouchableHighlight, etc.) with an onPress function make sure renderItem returns the Touchable as the topmost element.
GOOD:
BAD: