0 points

javascript - How to remove a item/index from a FlatList in react native? - Stack Overflow


dashboard

Sat Aug 08 2020 04:35:13 GMT+0000 (UTC)

Posted by @rdemo #javascript

deleteItemById = id => {
  const filteredData = this.state.data.filter(item => item.id !== id);
  this.setState({ data: filteredData });
}

render() {
  ...

  return (   
    <FlatList 
      data={data} // Assuming this is `this.state.data`
      keyExtractor={({item}) => item.id}                
      renderItem={({item}) => (
        <View style={styles.container}>
          <SwipeView
            ...
            onSwipedLeft={() => this.deleteItemById(item.id)}
            ...
          />
        </View>  
      )}
    />
  );
}
content_copy Copy

https://stackoverflow.com/questions/53855424/how-to-remove-a-item-index-from-a-flatlist-in-react-native/53856067#53856067