Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

React Native - Removing an item from async storage

$
0
0

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 1Error 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>  );

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>