I am using flatlist to display a list of items from the async storage. In the list of items, i want to be able to remove an item from the list which effectively removes the item from the async storage.
When i try to do this i get an error as shown here: Error 1 Error 2
Error 1 happens because the items are being compared so it can sort the list in ascending order and when the item is removed, the id returns null which produces this error.
Error 2 happens when i remove the last item from the list and i believe the error is related to the key extractor.
Async Storage: https://react-native-async-storage.github.io/async-storage/docs/api#removeitem
Code:
const removeItem = async (ID) => {
await AsyncStorage.removeItem(ID);
};
...
return (
<View>
<FlatList
data={itemsArray.sort((a, b) => (a.id > b.id ? 1 : -1)}
renderItem={renderItem}
keyExtractor={(product) => product.id}
/>
</View>
);
Via Active questions tagged javascript - Stack Overflow https://ift.tt/YT4Px3L
Comments
Post a Comment